]> rtime.felk.cvut.cz Git - git-ftp-sync.git/commitdiff
Fixed handling of refs if packed refs are used
authorroot <root@rtime.felk.cvut.cz>
Mon, 9 Mar 2009 12:10:46 +0000 (13:10 +0100)
committerroot <root@rtime.felk.cvut.cz>
Mon, 9 Mar 2009 12:10:46 +0000 (13:10 +0100)
git-ftp-sync

index 412dd3b642afc4311d7ac7ec49b451a4b00a9337..7d3528b4f9a39378e9548429f716efe5d44f0986 100755 (executable)
@@ -266,19 +266,18 @@ def perror(str):
 
 
 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)
@@ -304,11 +303,12 @@ if 'GIT_DIR' in os.environ:
         (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)