Skip to content

Commit

Permalink
add dry run for clone (#252)
Browse files Browse the repository at this point in the history
* add dry run for clone

* fix unit tests
  • Loading branch information
nosarthur authored Jul 14, 2023
1 parent f1758ca commit a5f8542
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
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.4.2",
version="0.16.5",
license="MIT",
description="Manage multiple git repos with sanity",
long_description=long_description,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a5f8542

Please sign in to comment.