简体   繁体   中英

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?

The .git/svn directory can be created if you run any git svn command in any repository - eg 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, eg

[ -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.

You should be able to use git svn info . Example output for a git-svn repository:

Path: .
URL: svn+ssh://url/path/to/something/trunk
Repository Root: svn+ssh://path/to/something
Repository UUID: c22683c8-8Bcb-47f9-aeb8-1c337d8f7a2d
Revision: 12345
Node Kind: directory
Schedule: normal
Last Changed Author: somebody
Last Changed Rev: 12345
Last Changed Date: 2012-01-24 16:38:36 -0800 (Tue, 24 Jan 2012)

And for a regular git repo:

Unable to determine upstream SVN information from working tree history

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM