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