Skip to content

Commit

Permalink
Fix bugs with multiple configured remotes; debug-log return code
Browse files Browse the repository at this point in the history
Pull Request: #18 (main)
  • Loading branch information
dimikot committed Dec 24, 2024
1 parent 9789184 commit 5e3c467
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion git-grok
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,22 @@ class Main:
# Returns current git folder remote (most often "origin").
#
def git_get_current_remote(self) -> str:
return self.shell(["git", "remote", "show"])
[_, symbolic_ref, _] = self.shell_no_throw(
["git", "symbolic-ref", "-q", "HEAD"]
)
if not symbolic_ref:
raise UserException(
'To run git-grok, you must be on a branch. Check your "git status".'
)
upstream = self.shell(
["git", "for-each-ref", "--format=%(upstream:short)", symbolic_ref]
)
m = re.match(r"([^/]+)/.+$", upstream)
if not m:
raise UserException(
f'Cannot extract remote from upstream "{upstream}" of symbolic ref "{symbolic_ref}".'
)
return m.group(1)

#
# Returns the current remote branch name on GitHub.
Expand Down

0 comments on commit 5e3c467

Please sign in to comment.