diff options
author | Seth Mason <seth@sethmason.com> | 2015-10-01 23:46:46 -0700 |
---|---|---|
committer | Seth Mason <smason@edgecast.com> | 2015-10-15 09:40:58 -0700 |
commit | 5997057f7abb6ced9891f5288f0e08d4b1b73a2f (patch) | |
tree | f28d6e1d3005d4fac1a753b565922f6e3fb97386 | |
parent | 42135ad00014387b6937242563b920a7cf640866 (diff) | |
download | git-sonar-5997057f7abb6ced9891f5288f0e08d4b1b73a2f.tar.gz git-sonar-5997057f7abb6ced9891f5288f0e08d4b1b73a2f.zip |
Fix #2 branches with same name in multiple remotes
Use `git config` to get the correct upstream remote and branch when you
have branch with the same name in multiple remotes (e.g. "origin/master"
and "coworker/master"). Uses awk which may be a problem?
-rwxr-xr-x | radar-base.sh | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..6a9c630 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -199,10 +199,15 @@ branch_ref() { remote_branch_name() { local localRef="\/$(branch_name)$" if [[ -n "$localRef" ]]; then - local remoteBranch="$(git for-each-ref --format='%(upstream:short)' refs/heads $localRef 2>/dev/null | grep $localRef)" - if [[ -n $remoteBranch ]]; then - printf '%s' $remoteBranch - return 0 + local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" + if [[ -n $remote ]]; then + local remoteBranch="$(git config --get-regexp "^branch\.${localRef}\.merge" | awk -F'/' '{print $NF}')" + if [[ -n $remoteBranch ]]; then + printf '%s/%s' $remote $remoteBranch + return 0 + else + return 1 + fi else return 1 fi |