Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if you're in a git-svn repo command line?

I'm trying to modify my bash prompt to print out if I'm in a git-svn repo. I see that git svn repos have a .git/svn folder, so I could check with:

# Find the top level git folder
_git_dir=`git rev-parse --show-toplevel 2> /dev/null`
# Find svn folder
_gsvn_check=`cd $_git_dir; ls .git/svn 2> /dev/null`

But then I noticed that my normal git repo has a .git/svn folder. Is there any way to know for sure that you're in git-svn?

like image 642
Andy Ray Avatar asked Jan 31 '12 19:01

Andy Ray


1 Answers

The .git/svn directory can be created if you run any git svn command in any repository - e.g. just running git svn info, as Carl Norum suggests will create it. However, a slightly better test might be that .git/svn exists and is non-empty, e.g.

[ -d .git/svn  ] && [ x != x"$(ls -A .git/svn/)" ] && echo Looks like git-svn

If you want a stricter test, you could look through the history of HEAD for any commit messages that contain a git-svn-id - essentially that's what git svn info is doing before it gives up. For example:

[ x != x"$(git log -n 1 --grep='^\s*git-svn-id' --oneline)" ] && echo "git-svn!"

... but it sounds as if that might be too slow for your use case.

The source code in git-svn.perl describes the layout of a git-svn repository in its different versions:

  • https://github.com/git/git/blob/master/git-svn.perl#L6433

... so you could write tests for all of those if you want to be careful to catch all the different versions.

like image 105
Mark Longair Avatar answered Nov 07 '22 07:11

Mark Longair