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?
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:
... so you could write tests for all of those if you want to be careful to catch all the different versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With