chiark / gitweb /
Use any of the branches that point to origin/HEAD if there are multiple
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 3 Jul 2014 14:25:24 +0000 (16:25 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 3 Jul 2014 14:25:24 +0000 (16:25 +0200)
'set-head origin --auto' fails if there are multiple branches that are the
same as origin/HEAD:

error: Multiple remote HEAD branches. Please choose one explicitly with:
  git remote set-head origin develop
  git remote set-head origin master

So we want to grab any of them, e.g. the first branch that it gives us, and
just use that as it will work just fine.

fdroidserver/common.py

index d0cc51d3ee2954c2516cb284ed54a9b2df443d15..69e6e68bdb9a0dede371fc7e39d16281b9415869 100644 (file)
@@ -480,7 +480,13 @@ class vcs_git(vcs):
                 # Recreate origin/HEAD as git clone would do it, in case it disappeared
                 p = SilentPopen(['git', 'remote', 'set-head', 'origin', '--auto'], cwd=self.local)
                 if p.returncode != 0:
-                    raise VCSException("Git remote set-head failed", p.output)
+                    lines = p.output.splitlines()
+                    if 'Multiple remote HEAD branches' not in lines[0]:
+                        raise VCSException("Git remote set-head failed", p.output)
+                    branch = lines[1].split(' ')[-1]
+                    p2 = SilentPopen(['git', 'remote', 'set-head', 'origin', branch], cwd=self.local)
+                    if p2.returncode != 0:
+                        raise VCSException("Git remote set-head failed", p.output + '\n' + p2.output)
                 self.refreshed = True
         # origin/HEAD is the HEAD of the remote, e.g. the "default branch" on
         # a github repo. Most of the time this is the same as origin/master.