{"thread":{"id":"6644","subject":"[PATCH] Use FETCH_HEAD to know where to rebase to after pull.","startedAt":"2007-02-03T21:29:30Z","lastAt":"2007-02-03T21:29:30Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"33487","messageId":"20070203212838.17474.42584.stgit@gandelf.nowhere.earth","threadId":"6644","inReplyTo":null,"subject":"[PATCH] Use FETCH_HEAD to know where to rebase to after pull.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-02-03T21:29:30Z","receivedAt":"2007-02-03T21:29:30Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"\nSince 'git fetch' already takes care of the branch.*.merge parameters,\nresolves the new tip of the parent branch and puts it in FETCH_HEAD,\nwe're better just taking it from there.\n\nThis fixes the regression on t1200-push-modified.sh.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/pull.py |    4 ++--\n stgit/git.py           |   23 ++++++++++++++++++++++-\n 2 files changed, 24 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 330cc25..e1aca87 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -73,8 +73,8 @@ def func(parser, options, args):\n     print 'Pulling from \"%s\"...' % repository\n     git.fetch(repository)\n     if (config.get('stgit.pull-does-rebase') == 'yes'):\n-        print \"rebasing to '%s'...\" % crt_series.get_parent_branch()\n-        git.reset(tree_id = git.rev_parse(crt_series.get_parent_branch()))\n+        print \"rebasing to '%s'...\" % git.fetch_head()\n+        git.reset(tree_id = git.fetch_head())\n     print 'done'\n \n     # push the patches back\ndiff --git a/stgit/git.py b/stgit/git.py\nindex 3d84e97..6769a9f 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -931,7 +931,8 @@ def remotes_local_branches(remote):\n         for line in stream:\n             # Only consider Pull lines\n             m = re.match('^Pull: (.*)\\n$', line)\n-            branches.append(refspec_localpart(m.group(1)))\n+            if m:\n+                branches.append(refspec_localpart(m.group(1)))\n         stream.close()\n     elif remote in __remotes_from_dir('branches'):\n         # old-style branches only declare one branch\n@@ -955,3 +956,23 @@ def identify_remote(branchname):\n \n     # if we get here we've found nothing\n     return None\n+\n+def fetch_head():\n+    \"\"\"Return the git id for the tip of the parent branch as left by\n+    'git fetch'.\n+    \"\"\"\n+\n+    fetch_head=None\n+    stream = open(os.path.join(basedir.get(), 'FETCH_HEAD'), \"r\")\n+    for line in stream:\n+        # Only consider lines not tagged not-for-merge\n+        m = re.match('^([^\\t]*)\\t\\t', line)\n+        if m:\n+            if fetch_head:\n+                raise GitException, \"StGit does not support multiple FETCH_HEAD\"\n+            else:\n+                fetch_head=m.group(1)\n+    stream.close()\n+\n+    # here we are sure to have a single fetch_head\n+    return fetch_head\n"}]}