Skip to content

Commit a439e1d

Browse files
Allow fetch subcommand to work with empty arguments
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 5278a7c commit a439e1d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

git_sim/commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def commit(
110110

111111
def fetch(
112112
remote: str = typer.Argument(
113-
...,
113+
default=None,
114114
help="The name of the remote to fetch from",
115115
),
116116
branch: str = typer.Argument(
117-
...,
117+
default=None,
118118
help="The name of the branch to fetch",
119119
),
120120
):

git_sim/fetch.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ def __init__(self, remote: str, branch: str):
2020
self.branch = branch
2121
settings.max_branches_per_commit = 2
2222

23-
if self.remote not in self.repo.remotes:
23+
if self.remote and self.remote not in self.repo.remotes:
2424
print("git-sim error: no remote with name '" + self.remote + "'")
2525
sys.exit(1)
2626

2727
def construct(self):
2828
if not settings.stdout and not settings.output_only_path and not settings.quiet:
2929
print(
30-
f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.remote} {self.branch}"
30+
f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.remote if self.remote else ''} {self.branch if self.branch else ''}"
3131
)
3232

33+
if not self.remote:
34+
self.remote = "origin"
35+
if not self.branch:
36+
self.branch = self.repo.active_branch.name
37+
3338
self.show_intro()
3439

3540
git_root = self.repo.git.rev_parse("--show-toplevel")
@@ -42,7 +47,12 @@ def construct(self):
4247
for r2 in self.repo.remotes:
4348
if r1.name == r2.name:
4449
r2.set_url(r1.url)
45-
self.repo.git.fetch(self.remote, self.branch)
50+
51+
try:
52+
self.repo.git.fetch(self.remote, self.branch)
53+
except git.GitCommandError as e:
54+
print(e)
55+
sys.exit(1)
4656

4757
# local branch doesn't exist
4858
if self.branch not in self.repo.heads:

0 commit comments

Comments
 (0)