views:

534

answers:

3

I've got some shell stuff set up that dynamically defines aliases depending on what sort of VC repo the CWD contains -- so, for example, 'd' runs 'svn diff' or 'git diff', depending. (Based on this blog post, if anybody is interested...)

I'd like to define some aliases differently depending on whether I'm in a git repo versus a git-svn repo. Is there an easy way to tell the difference between the two?

+5  A: 

You can probably use the output of the git config command to differentiate between a git and git-svn repo.

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

should return the svn URL being synced to, if there is one.

codelogic
A: 

There is also a branch called trunk and and a branch called trunk@[REV]. However, I think codelogics approach is easier and cleaner.

Kafka
+5  A: 

You should be a bit careful when deciding which repositories exactly are git-svn repositories. A repository may contain more than one svn repository.

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

Codelogic's answer will only work if there is an svn repository called svn -- there's no requirement that that is true.

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

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

That will find any configured git-svn repository, whatever they're called. It'll exit with status 0 if there is a match, and 1 if there is no match.

But, this doesn't mean that the svn repository is really used. It might also be that someone has imported an svn repository, but uses is as a submodule or as a sub-tree merge, or even not at all. If metadata in the git-svn repository has been turned on, you can see if any svn revision has been used in the current HEAD by using something like this:

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

But that's perhaps a bit too convoluted. You decide.

Pieter
thanks - the rev-list bit is too convoluted for my purposes; after poking around a bit more on my own, i'll probably just do 'if [ -d .git/svn ]' and go from there. i realize it won't handle the general case, but it covers all of mine.thanks again.
genehack