Skip to content

Makefile: Fix rebuilds not properly updating git/libgit2 repos

Patrick Steinhardt requested to merge pks-makefile-fix-rebuild-fetches into master

When rebuilding git and libgit2, we first do a git-fetch(1) followed by a git-switch(1). The fetch doesn't use a remote name though but a repository URL, so it won't make use of any revspec and thus it won't create a branch. As a result, the subsequent git-switch(1) will fail to find the branch.

There's also a second issue: if the reference at hand exists already, then we won't ever update it. This is fine for hashes and for tags as they're unlikely to change. But if we use a branch, then that branch won't ever get updated even if the respective version file gets forcefully deleted to cause a rebuild.

Fix both issues by reworking the update logic. Right now, the logic to fetch/clone is kind of duplicated, which makes it harder than necessary to properly bring both under the same hood and make it work the same both on initial clone as well as subsequent fetches. Instead, we now just initialize a new git directory in case it doesn't exist and then always do the same fetch in both cases. Given that this fetch does not create any refs except for FETCH_HEAD, we then do a git-switch(1) to FETCH_HEAD.

By always doing the fetch we ensure that even if a branch was given, it will get updated accordingly. And because we now switch to FETCH_HEAD, there's no issue anymore with finding the correct branch.

Supersedes !3185 (closed)

Merge request reports