How do you know if you are on the git-svn repo command line?

I am trying to change the bash prompt to print if I am in the git-svn repository. I see that git svn repos has a .git / svn folder, so I can check:

# 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 there is a .git / svn folder in my regular git repository. Is there any way to know for sure that you are in git-svn?

+4
source share
2 answers

The .git/svn directory can be created if you run any git svn in any repository - for example. just git svn info , as Carl Norum offers , will create it. However, a slightly better test might be that .git/svn exists and is not empty, for example

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

If you need a more rigorous test, you can view the HEAD history for any commit messages containing git-svn-id - essentially what git svn info does before it refuses. For instance:

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

... but it sounds like it might be too slow for your use case.

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

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

+3
source

You can use git svn info . Sample output for 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 regular git repo:

 Unable to determine upstream SVN information from working tree history 
+1
source

Source: https://habr.com/ru/post/1394047/


All Articles