chiark / gitweb /
Use FETCH_HEAD to know where to rebase to after pull. master
authorYann Dirson <ydirson@altern.org>
Sat, 3 Feb 2007 21:29:30 +0000 (22:29 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sat, 3 Feb 2007 22:15:19 +0000 (22:15 +0000)
Since 'git fetch' already takes care of the branch.*.merge parameters,
resolves the new tip of the parent branch and puts it in FETCH_HEAD,
we're better just taking it from there.

This fixes the regression on t1200-push-modified.sh.

Signed-off-by: Yann Dirson <ydirson@altern.org>
stgit/commands/pull.py
stgit/git.py

index 330cc256d3f7bf410e9ade341dc1b4a3963504bc..b63ef7a55ed7d197aaec53e8ebd84b34e303db61 100644 (file)
@@ -73,8 +73,8 @@ def func(parser, options, args):
     print 'Pulling from "%s"...' % repository
     git.fetch(repository)
     if (config.get('stgit.pull-does-rebase') == 'yes'):
-        print "rebasing to '%s'..." % crt_series.get_parent_branch()
-        git.reset(tree_id = git.rev_parse(crt_series.get_parent_branch()))
+        print 'rebasing to "%s"...' % git.fetch_head()
+        git.reset(tree_id = git.fetch_head())
     print 'done'
 
     # push the patches back
index 3d84e97a4bbb05cf492e572cece4ccaa14bff317..6769a9f574417827642b22b1768e9852ca3e8019 100644 (file)
@@ -931,7 +931,8 @@ def remotes_local_branches(remote):
         for line in stream:
             # Only consider Pull lines
             m = re.match('^Pull: (.*)\n$', line)
-            branches.append(refspec_localpart(m.group(1)))
+            if m:
+                branches.append(refspec_localpart(m.group(1)))
         stream.close()
     elif remote in __remotes_from_dir('branches'):
         # old-style branches only declare one branch
@@ -955,3 +956,23 @@ def identify_remote(branchname):
 
     # if we get here we've found nothing
     return None
+
+def fetch_head():
+    """Return the git id for the tip of the parent branch as left by
+    'git fetch'.
+    """
+
+    fetch_head=None
+    stream = open(os.path.join(basedir.get(), 'FETCH_HEAD'), "r")
+    for line in stream:
+        # Only consider lines not tagged not-for-merge
+        m = re.match('^([^\t]*)\t\t', line)
+        if m:
+            if fetch_head:
+                raise GitException, "StGit does not support multiple FETCH_HEAD"
+            else:
+                fetch_head=m.group(1)
+    stream.close()
+
+    # here we are sure to have a single fetch_head
+    return fetch_head