Skip to content

Commit a0f57f9

Browse files
Add --set-upstream flag for push subcommand
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent ce8999a commit a0f57f9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/git_sim/commands.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,15 @@ def push(
240240
default=None,
241241
help="The name of the branch to push",
242242
),
243+
set_upstream: bool = typer.Option(
244+
False,
245+
"--set-upstream",
246+
help="Map the local branch to the specified upstream branch",
247+
),
243248
):
244249
from git_sim.push import Push
245250

246-
scene = Push(remote=remote, branch=branch)
251+
scene = Push(remote=remote, branch=branch, set_upstream=set_upstream)
247252
handle_animations(scene=scene)
248253

249254

src/git_sim/push.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717

1818
class Push(GitSimBaseCommand):
19-
def __init__(self, remote: str = None, branch: str = None):
19+
def __init__(self, remote: str = None, branch: str = None, set_upstream: bool = False):
2020
super().__init__()
2121
self.remote = remote
2222
self.branch = branch
23+
self.set_upstream = set_upstream
2324
settings.max_branches_per_commit = 2
2425

2526
if self.remote and self.remote not in self.repo.remotes:
2627
print("git-sim error: no remote with name '" + self.remote + "'")
2728
sys.exit(1)
2829

29-
self.cmd += f"{type(self).__name__.lower()} {self.remote if self.remote else ''} {self.branch if self.branch else ''}"
30+
self.cmd += f"{type(self).__name__.lower()} {'--set-upstream ' if self.set_upstream else ''}{self.remote if self.remote else ''} {self.branch if self.branch else ''}"
3031

3132
def construct(self):
3233
if not settings.stdout and not settings.output_only_path and not settings.quiet:

0 commit comments

Comments
 (0)