Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dry run option for gita add #210

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ def _path_name(name: str) -> str:
def f_add(args: argparse.Namespace):
repos = utils.get_repos()
paths = args.paths
dry_run = args.dry_run
groups = utils.get_groups()
if args.recursive or args.auto_group:
paths = (p.rstrip(os.path.sep) for p in chain.from_iterable(
glob.glob(os.path.join(p, '**/'), recursive=True)
for p in args.paths))
new_repos = utils.add_repos(repos, paths, include_bare=args.bare,
exclude_submodule=args.skip_submodule)
exclude_submodule=args.skip_submodule,
dry_run=dry_run)
if dry_run:
return
if new_repos and args.auto_group:
new_groups = utils.auto_group(new_repos, args.paths)
if new_groups:
Expand Down Expand Up @@ -389,6 +393,7 @@ def main(argv=None):
p_add = subparsers.add_parser('add', description='add repo(s)',
help='add repo(s)')
p_add.add_argument('paths', nargs='+', type=_path_name, help="repo(s) to add")
p_add.add_argument('-n','--dry-run', action='store_true', help='dry run')
p_add.add_argument('-g','--group',
choices=utils.get_groups(),
help="add repo(s) to the specified group")
Expand Down
5 changes: 5 additions & 0 deletions gita/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def _make_name(path: str, repos: Dict[str, Dict[str, str]],
def add_repos(repos: Dict[str, Dict[str, str]], new_paths: List[str],
include_bare=False,
exclude_submodule=False,
dry_run=False,
) -> Dict[str, Dict[str, str]]:
"""
Write new repo paths to file; return the added repos.
Expand All @@ -291,6 +292,10 @@ def add_repos(repos: Dict[str, Dict[str, str]], new_paths: List[str],
new_repos = {}
if new_paths:
print(f"Found {len(new_paths)} new repo(s).")
if dry_run:
for p in new_paths:
print(p)
return {}
name_counts = Counter(
os.path.basename(os.path.normpath(p)) for p in new_paths
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name='gita',
packages=['gita'],
version='0.16.1',
version='0.16.1.1',
license='MIT',
description='Manage multiple git repos with sanity',
long_description=long_description,
Expand Down