def update_ref(hash):
- remote = "ftp"
- branch = "master"
- if (not os.path.exists("refs/remotes/"+remote)):
- os.makedirs("refs/remotes/"+remote)
- file("refs/remotes/"+remote+"/"+branch, "w").write(newrev+"\n")
+ cmd = "git update-ref refs/remotes/ftp/master %s"%(hash)
+ #print "Runnging", cmd
+ os.system(cmd)
def add_to_change_list(changes, git_command, oldrev, newrev):
# Read changes
+ ##print "Running: ", git_command
gitdiff = Popen(git_command,
stdout=PIPE, stderr=PIPE, close_fds=True, shell=True)
change_re = re.compile("(\S+)\s+(.*)$");
for line in gitdiff.stdout:
- #print line,
+ ##print line,
m = change_re.match(line)
if (m):
change = RepoChange(m.group(1), m.group(2), oldrev, newrev, options)
(oldrev, newrev, refname) = line.split()
if refname == "refs/heads/master":
try:
- oldrev=file("refs/remotes/ftp/master").readline().strip();
- git_command = "/usr/bin/git diff --name-status %s %s"%(oldrev, newrev)
+ oldrev=os.popen('git show-ref --hash refs/remotes/ftp/master').read().strip()
+ if not oldrev: raise IOError, "No ref" # Simulate failure if the branch doesn't exist
+ git_command = "git diff --name-status %s %s"%(oldrev, newrev)
except IOError:
# We are run for the first time, so (A)dd all files in the repo.
- oldrev = None;
+ oldrev = None
git_command = r"git ls-tree -r --name-only %s | sed -e 's/\(.*\)/A \1/'"%(newrev);
add_to_change_list(changes, git_command, oldrev, newrev)