From fa3cceb8e84898ac50d0110e0e29a0d54b5022d4 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 10 Oct 2021 17:09:29 +0200 Subject: [PATCH] git prune branches in case of failure git branches can be namespaces like directories on a filesystem and are represented like that. Due to that there can't be a branch with the same name as a namespace, i.e. foo and foo/bar. If upstream moves from a branch to namespace, we need to prune the old branch before fetching the new one. This broke organic maps: From https://github.com/organicmaps/organicmaps * [new branch] android/huawei -> origin/android/huawei error: cannot lock ref 'refs/remotes/origin/fixes/all': 'refs/remotes/origin/fixes' exists; cannot create 'refs/remotes/origin/fixes/all' ! [new branch] fixes/all -> origin/fixes/all (unable to update local ref) e2ac324b95..320a1db39b master -> origin/master * [new tag] 2021.10.09-2-android -> 2021.10.09-2-android error: some local refs could not be updated; try running 'git remote prune origin' to remove any old, conflicting branches --- fdroidserver/common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index c413f239..389dfe8a 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1167,6 +1167,9 @@ class vcs_git(vcs): p = self.git(['fetch', 'origin'], cwd=self.local) if p.returncode != 0: raise VCSException(_("Git fetch failed"), p.output) + p = self.git(['remote', 'prune', 'origin'], output=False, cwd=self.local) + if p.returncode != 0: + raise VCSException(_("Git prune failed"), p.output) p = self.git(['fetch', '--prune', '--tags', '--force', 'origin'], output=False, cwd=self.local) if p.returncode != 0: raise VCSException(_("Git fetch failed"), p.output)