tags:

views:

143

answers:

3

This python script is the best I have come up with so far. I just hacked it together and on a cursory first couple uses, seems to be acting correctly, but I can't help but feel there is an easier way to do this or even something built in (though I have searched and searched).

Thanks for the help.

#!/usr/bin/env python                                                                            
import sys
import subprocess

s = subprocess.Popen("git svn log --show-commit --oneline".split(" "),
                     stdout=subprocess.PIPE)

# Grab the last svn commit's data                                                                
revision, sha, message = s.stdout.readlines().pop(0).split(" | ")

# Grab display of commits since svn rebase                                                       
s = subprocess.Popen(("git log %s..HEAD --oneline" % sha).split(" "),
                     stdout=subprocess.PIPE)
log = s.stdout.read().strip()

if len(log.splitlines()) > 0:
    print ("%d commits ahead of svn. To push them to svn, use 'git svn dcommit'.\n"
               % len(log.splitlines()))
    print log
else:
    print "No local commits that need 'git svn dcommit'"
sys.exit(0)
+2  A: 

First, do a git branch -a to list all the remote branches:

$ git branch -a
  git-svn

For me, only the git-svn branch is listed, but you may have different names depending on what options you passed to git svn clone. Then, use

git log git-svn..

(substituting your appropriate name for git-svn). The above command (note the two trailing dots ..) shows all the commits on the current branch since the nearest common ancestor of the current branch and the git-svn branch.

Greg Hewgill
This command does not work for me, git reports fatal ambiguities. I tried "git log -- git-svn.." and "git log -- git-svn..HEAD" and neither display the proper commits. Neither does switching the order of "--" and "git-svn..".
nicholas
@nicholas: that command works for me, I'm not sure what kind of "fatal ambiguities" git might be reporting for you. If you do a `git branch -a`, how many times is `git-svn` listed?
Greg Hewgill
See my answer to my own question. I don't have a git-svn branch, instead I have a remotes/trunk. Not sure why our setups differ... I used the standard layout when cloning.
nicholas
My setup might be different from yours because I specifically cloned *just* the trunk and not any other Subversion branches. In any case, my answer has been updated to apply to any situation.
Greg Hewgill
A: 

After playing around with Greg's suggestion, I ended up with this:

git log remotes/trunk.. --oneline

which I will either alias or wrap in a small script.

The reason why this works and his suggestion didn't is that my remopte svn branch is remotes/trunk not git-svn. I don't know if this is standard or not, especially since Greg assumed git-svn.

nicholas
I've updated my answer with more info about git-svn remote tracking branch names.
Greg Hewgill
A: 

Nice. Based on the info here, I use:

git config alias.svn-status \!"git log git-svn.. --oneline |wc|perl -ne 'tr/ //s;s/^ //;(\$commits)=split(/ /,\$_,2);print \"Your branch is ahead of git-svn by \$commits commits\n\"'"

This assumes the standard git-svn default remote repo nomenclature.

jstevenco