Skip to content

Commit

Permalink
Better handle multiple ssh remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Scheirle committed Apr 2, 2024
1 parent e5f1b63 commit 287cc5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git_gerrit/cli/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def main(self):
if b.remote_name == "":
print("Current branch has no remote, cannot push to gerrit")
return 1
cmd = ["push", GitConfig.remote(), f"HEAD:refs/for/{b.remote_name}", "-o", f"hashtag=branch:{b.local_name}"] + self.options
cmd = ["push", b.remote, f"HEAD:refs/for/{b.remote_name}", "-o", f"hashtag=branch:{b.local_name}"] + self.options
git[cmd].run_fg()
5 changes: 4 additions & 1 deletion git_gerrit/utils/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class LocalBranch:
def __init__(self, ref: str):
self.local_name = git["rev-parse", "--abbrev-ref", ref]().strip()
self.remote_ref = git["for-each-ref", "--format=%(upstream:short)", ref]().strip()
self.remote_name = self.remote_ref.replace(f"{GitConfig.remote()}/", "")
split = self.remote_ref.split("/")
assert len(split) > 0 and len(split) <= 2, f"Unexpected/supported remote name {self.remote_ref}"
self.remote = split[0]
self.remote_name = split[1] if len(split) > 1 else ""

def has_remote(self):
return self.remote_ref != ""
Expand Down

0 comments on commit 287cc5d

Please sign in to comment.