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.

Merge request reports

Loading