Skip to content

Commit

Permalink
Update __fish_git_prompt.fish to handle git-svn better
Browse files Browse the repository at this point in the history
Git-svn remotes can have a prefix for their remotes. If I set a prefix
of 'svn/' then my remote trunk branch is called svn/trunk. Update the
script to use the svn-remote.*.fetch key to figure out how the 'trunk'
branch is mapped into the remotes namespace and apply this to the
current branch. This assumes branches are mapped into the same
namespace, which is likely. It also doesn't work for tags, but neither
did the old code.
  • Loading branch information
lilyball authored and ridiculousfish committed Jul 14, 2012
1 parent 257e9b0 commit b1281c3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions share/functions/__fish_git_prompt.fish
Expand Up @@ -78,6 +78,7 @@
function __fish_git_prompt_show_upstream --description "Helper function for __fish_git_prompt"
# Ask git-config for some config options
set -l svn_remote
set -l svn_prefix
set -l upstream git
set -l legacy
set -l verbose
Expand All @@ -90,6 +91,8 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
test -n "$__fish_git_prompt_showupstream"; or return
case svn-remote.'*'.url
set svn_remote $svn_remote $value
set -l remote_prefix (/bin/sh -c 'echo "${1%.url}"' -- $key)
set svn_prefix $svn_prefix $remote_prefix
if test -n "$svn_url_pattern"
set svn_url_pattern $svn_url_pattern"\|$value"
else
Expand Down Expand Up @@ -122,8 +125,16 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
if test (count $svn_upstream) -ne 0
echo $svn_upstream[-1] | read -l _ svn_upstream _
set svn_upstream (echo $svn_upstream | sed 's/@.*//')
for remote in $svn_remote
set svn_upstream (/bin/sh -c 'echo "${1#$2}"' -- $svn_upstream $remote)
set -l cur_prefix
for i in (seq (count $svn_remote))
set -l remote $svn_remote[$i]
set -l mod_upstream (/bin/sh -c 'echo "${1#$2}"' -- $svn_upstream $remote)
if test "$svn_upstream" != "$mod_upstream"
# we found a valid remote
set svn_upstream $mod_upstream
set cur_prefix $svn_prefix[$i]
break
end
end

if test -z "$svn_upstream"
Expand All @@ -139,6 +150,12 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
else
set upstream $svn_upstream
end
set -l fetch_val (git config "$cur_prefix".fetch)
if test -n "$fetch_val"
set -l IFS :
echo "$fetch_val" | read -l trunk pattern
set upstream (/bin/sh -c 'echo "${1%/$2}"' -- $pattern $trunk)/$upstream
end
end
else
if test $upstream = svn+git
Expand Down

0 comments on commit b1281c3

Please sign in to comment.