From 794e73cb4469c30bd830b333597a6932da1254f1 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 8 Nov 2017 18:45:18 +0000 Subject: git.py source plugin: Prune remote-tracking branches when fetching I noticed this issue when running `bst track` on a system that contained GLIBC. The following error occurred: [--:--:--] START [gnu-toolchain/stage2-glibc.bst]: Tracking release/2.25/master from git://git.baserock.org/delta/glibc Running host command /home/fedora/src/baserock/definitions/.cache/buildstream/sources/git/git___git_baserock_org_delta_glibc: /usr/bin/git fetch origin [--:--:--] STATUS [gnu-toolchain/stage2-glibc.bst]: Running host command /usr/bin/git fetch origin error: cannot lock ref 'refs/heads/hjl/memcpy/dpdk/master': 'refs/heads/hjl/memcpy' exists; cannot create 'refs/heads/hjl/memcpy/dpdk/master' From git://git.baserock.org/delta/glibc ! [new branch] hjl/memcpy/dpdk/master -> hjl/memcpy/dpdk/master (unable to update local ref) error: cannot lock ref 'refs/heads/hjl/x86/master': 'refs/heads/hjl/x86' exists; cannot create 'refs/heads/hjl/x86/master' ! [new branch] hjl/x86/master -> hjl/x86/master (unable to update local ref) error: cannot lock ref 'refs/heads/hjl/x86/math': 'refs/heads/hjl/x86' exists; cannot create 'refs/heads/hjl/x86/math' ! [new branch] hjl/x86/math -> hjl/x86/math (unable to update local ref) error: cannot lock ref 'refs/heads/hjl/x86/optimize': 'refs/heads/hjl/x86' exists; cannot create 'refs/heads/hjl/x86/optimize' ! [new branch] hjl/x86/optimize -> hjl/x86/optimize (unable to update local ref) error: some local refs could not be updated; try running 'git remote prune origin' to remove any old, conflicting branches git source at gnu-toolchain/stage2-glibc.bst [line 4 column 2]: Failed to fetch from remote git repository: git://git.baserock.org/delta/glibc The issue here is that my local clone had old remote-tracking refs which conflicted with newer upstream refs. For example, there used to be a ref named `hlj/memcpy` which I had mirrored locally. This has been deleted and now a ref exists named `hlj/memcpy/dpdk/master`. The new ref cannot be pulled because Git considers it to conflict with the old one. The solution is to use `git fetch --prune` when updating so that Git removes any outdated remote-tracking refs before trying to create any new ones. --- buildstream/plugins/sources/git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py index afbca252c..baf159d82 100644 --- a/buildstream/plugins/sources/git.py +++ b/buildstream/plugins/sources/git.py @@ -108,7 +108,7 @@ class GitMirror(): (str(self.source), self.url, tmpdir, self.mirror)) from e def fetch(self): - self.source.call([self.source.host_git, 'fetch', 'origin'], + self.source.call([self.source.host_git, 'fetch', 'origin', '--prune'], fail="Failed to fetch from remote git repository: {}".format(self.url), cwd=self.mirror) -- cgit v1.2.1