Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically tell difference between git-svn and git repos?

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?

like image 262
genehack Avatar asked Dec 30 '22 06:12

genehack


1 Answers

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.

like image 190
Pieter Avatar answered Jan 01 '23 20:01

Pieter