Programmatically spot the difference between git-svn and git repos?

I have shell material that dynamically defines aliases depending on what type of VC repository CWD contains - so, for example, 'd' starts 'svn diff' or 'git diff', depending on, (Based on this blog post if anyone is interested ...)

I would like to define some aliases differently depending on whether I am in the git and git-svn repo repositories. Is there an easy way to talk about the difference between the two?

+4
source share
3 answers

You have to be a little careful when deciding which repositories are exactly git-svn repositories. A repository can contain more than one svn repository.

Kafka's solution will only work if the svn repository has been cloned with the -s or -std-layout option, which actually has a trunk branch.

The codological answer will only work if there is an svn repository named svn - there is no requirement that this be true.

The easiest way to check if svn-remote is in the config:

 $ git config --get-regexp ^svn-remote 

This will find any configured git-svn repository no matter what they invoke. It will exit with status 0 if there is a match, and 1 if there is no match.

But this does not mean that the svn repository is actually used. It may also be that someone imported the svn repository, but uses it as a submodule or as a merge with a tree tree, or even not at all. If the metadata in the git-svn repository is included, you can see if there was any version of svn in the current HEAD using something like this:

 $ git rev-list -1 --grep='git-svn-id' HEAD 

But this is perhaps too confusing. You decide.

+5
source

Perhaps you can use the output of the git config command to separate between git and git-svn repositories.

 git config --get svn-remote.svn.url 

should return the svn url synchronized with, if any.

+5
source

There is also a branch called trunk, and a branch called trunk @ [REV]. However, I believe that the codological approach is simpler and cleaner.

0
source

All Articles