From dcb74c74c147c8aa7edba727c02b3a109b922716 Mon Sep 17 00:00:00 2001 From: Dong Zhou Date: Sun, 5 Sep 2021 22:21:25 -0400 Subject: [PATCH] add gita group -p option to modify group path #187 (#190) --- gita/__main__.py | 23 ++++++++++++++++------- gita/utils.py | 1 - setup.py | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gita/__main__.py b/gita/__main__.py index cea1bc5..d38e78d 100644 --- a/gita/__main__.py +++ b/gita/__main__.py @@ -50,7 +50,9 @@ def _path_name(name: str) -> str: """ Return absolute path without trailing / """ - return os.path.abspath(name).rstrip(os.path.sep) + if name: + return os.path.abspath(name).rstrip(os.path.sep) + return '' def f_add(args: argparse.Namespace): @@ -236,15 +238,19 @@ def f_group(args: argparse.Namespace): elif cmd == 'add': gname = args.gname if gname in groups: - # TODO: update group path as well gname_repos = set(groups[gname]['repos']) gname_repos.update(args.to_group) groups[gname]['repos'] = sorted(gname_repos) + if 'gpath' in args: + groups[gname]['path'] = args.gpath utils.write_to_groups_file(groups, 'w') else: - # TODO: update group path as well + gpath = '' + if 'gpath' in args: + gpath = args.gpath utils.write_to_groups_file( - {gname: {'repos': sorted(args.to_group), 'path': ''}}, + {gname: {'repos': sorted(args.to_group), + 'path': gpath}}, 'a+') elif cmd == 'rmrepo': gname = args.gname @@ -585,8 +591,12 @@ def main(argv=None): dest='gname', type=partial(_group_name, exclude_old_names=False), metavar='group-name', - required=True, - help="group name") + required=True) + pg_add.add_argument('-p', '--path', + dest='gpath', + type=_path_name, + metavar='group-path') + pg_rmrepo = group_cmds.add_parser('rmrepo', description='remove repo(s) from a group.') pg_rmrepo.add_argument('to_rm', nargs='+', @@ -679,6 +689,5 @@ def main(argv=None): else: p.print_help() # pragma: no cover - if __name__ == '__main__': main() # pragma: no cover diff --git a/gita/utils.py b/gita/utils.py index d0f38da..7a1020c 100644 --- a/gita/utils.py +++ b/gita/utils.py @@ -330,7 +330,6 @@ def _generate_dir_hash(repo_path: str, paths: List[str]) -> Tuple[ For example, if `repo_path` is /a/b/c/d/here, and one of `paths` is /a/b/ then return (b, c, d) """ - print(paths, repo_path, '*'*5) for p in paths: rel = get_relative_path(repo_path, p)[:-1] if rel is not None: diff --git a/setup.py b/setup.py index 232dabe..555cf13 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='gita', packages=['gita'], - version='0.15.6.4', + version='0.15.7', license='MIT', description='Manage multiple git repos with sanity', long_description=long_description,