diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 31f714da927511..78ee12e7be5569 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -94,8 +94,8 @@ __gitdir () __git_ps1_show_upstream () { local key value - local svn_remote svn_url_pattern count n - local upstream=git legacy="" verbose="" + local count + local upstream=git upstream_path="" legacy="" verbose="" svn_remote=() # get some config options from git-config @@ -110,8 +110,6 @@ __git_ps1_show_upstream () fi ;; svn-remote.*.url) - svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value" - svn_url_pattern+="\\|$value" upstream=svn+git # default upstream is SVN if available, else git ;; esac @@ -130,26 +128,18 @@ __git_ps1_show_upstream () case "$upstream" in git) upstream="@{upstream}" ;; svn*) - # get the upstream from the "git-svn-id: ..." in a commit message - # (git-svn uses essentially the same procedure internally) - local svn_upstream=($(git log --first-parent -1 \ - --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null)) - if [[ 0 -ne ${#svn_upstream[@]} ]]; then - svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]} - svn_upstream=${svn_upstream%@*} - local n_stop="${#svn_remote[@]}" - for ((n=1; n <= n_stop; n++)); do - svn_upstream=${svn_upstream#${svn_remote[$n]}} - done - - if [[ -z "$svn_upstream" ]]; then - # default branch name for checkouts with no layout: - upstream=${GIT_SVN_ID:-git-svn} - else - upstream=${svn_upstream#/} - fi - elif [[ "svn+git" = "$upstream" ]]; then - upstream="@{upstream}" + upstream_path="$(git config --get-regexp 'svn-remote.*(fetch|tags|branches)$' | + cut -d' ' -f2 | cut -d: -f1)" + if [[ -z "$upstream_path" ]] + then + # default branch name for checkouts with no layout: + upstream=${GIT_SVN_ID:-git-svn} + else + upstream="$(git log -1 --pretty=format:"%B" --first-parent \ + --grep=git-svn-id HEAD | + grep -oE '(tags/)?[^/]+@' --color=never | + tr -d "@")" + [ -n "$upstream" ] || upstream="@{upstream}" fi ;; esac