From a5f8542a5370ae4a43e2504b6e4c34d1a2d94e55 Mon Sep 17 00:00:00 2001 From: Dong Zhou Date: Fri, 14 Jul 2023 09:02:08 -0400 Subject: [PATCH] add dry run for clone (#252) * add dry run for clone * fix unit tests --- gita/__main__.py | 16 ++++++++++++++++ setup.py | 2 +- tests/test_main.py | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gita/__main__.py b/gita/__main__.py index 4e0c450..3d091c6 100644 --- a/gita/__main__.py +++ b/gita/__main__.py @@ -149,10 +149,20 @@ def f_info(args: argparse.Namespace): def f_clone(args: argparse.Namespace): + + if args.dry_run: + if args.from_file: + for url, repo_name, abs_path in utils.parse_clone_config(args.clonee): + print(f"git clone {url} {abs_path}") + else: + print(f"git clone {args.clonee}") + return + if args.directory: path = args.directory else: path = Path.cwd() + if not args.from_file: subprocess.run(["git", "clone", args.clonee], cwd=path) return @@ -499,6 +509,12 @@ def main(argv=None): action="store_true", help="clone repo(s) in their original paths", ) + p_clone.add_argument( + "-n", + "--dry-run", + action="store_true", + help="If set, show command without execution", + ) p_clone.set_defaults(func=f_clone) p_rename = subparsers.add_parser( diff --git a/setup.py b/setup.py index 7a8030a..d62cb5f 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="gita", packages=["gita"], - version="0.16.4.2", + version="0.16.5", license="MIT", description="Manage multiple git repos with sanity", long_description=long_description, diff --git a/tests/test_main.py b/tests/test_main.py index dbd4236..6d05867 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -186,6 +186,7 @@ def test_clone_with_url(mock_run): args.preserve_path = None args.directory = "/home/xxx" args.from_file = False + args.dry_run = False __main__.f_clone(args) cmds = ["git", "clone", args.clonee] mock_run.assert_called_once_with(cmds, cwd=args.directory) @@ -204,6 +205,7 @@ def test_clone_with_config_file(*_): args.preserve_path = False args.directory = None args.from_file = True + args.dry_run = False __main__.f_clone(args) mock_run = utils.run_async.mock assert mock_run.call_count == 1 @@ -224,6 +226,7 @@ def test_clone_with_preserve_path(*_): args.directory = None args.from_file = True args.preserve_path = True + args.dry_run = False __main__.f_clone(args) mock_run = utils.run_async.mock assert mock_run.call_count == 1