From fdc21b961602843f8d1e24a7d772929f8c6032fc Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 16 Nov 2023 07:08:48 -0500 Subject: acid: source: Prevent creation of local branches/refs Previously (and as is the default behavior in git), when cloning fresh cache repositories for user services, we would acquire current remote-tracking branches, tags, and a local branch tracking origin/HEAD. In practice, this local branch becomes vestigial. As we fetch updates, we always checkout by commit hash and leave the repository in a detached HEAD. The local branch reference is therefore never updated. This is fine for the functionality of ACID. However, if querying the repo for information about the current version, it is possible for tools like `git describe` to describe HEAD in terms of this stale branch ref. Now, when we clone a repository arrange for there to be no 'local' branch references. Only remote-tracking branches and tags. Remote-tracking branches are properly updated and removed by our fetch command. Additionally, prevent the remote 'origin/HEAD' symbolic ref, since it would be mildly confusing for it to pop up to the user as well. In effect, we limit our ref namespace only to branches and tags that actually exist on the remote host. Signed-off-by: Malfurious --- acid/acid-source | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/acid/acid-source b/acid/acid-source index 351d3d0..8c62c44 100755 --- a/acid/acid-source +++ b/acid/acid-source @@ -37,13 +37,24 @@ if ! echo "$1" | grep -Eq '^[-_a-z0-9]*$'; then fi if ! [ -d "$1" ]; then + # New repository git clone "$2" "$1" >&2 || fail - touch "$1/.git/previous_hash" - touch "$1/.git/previous_slug" + cd "$1" + + # Strip down to tags and remote refs only + git remote set-head origin --delete >/dev/null 2>&1 + git checkout HEAD~0 >/dev/null 2>&1 + git for-each-ref --format='delete %(refname)' refs/heads \ + | git update-ref --stdin >/dev/null 2>&1 + + # Init cyche metadata + touch ".git/previous_hash" + touch ".git/previous_slug" +else + # Existing repository + cd "$1" fi -cd "$1" - git remote set-url origin "$2" >&2 # pick up url changes git fetch --all --prune >&2 || fail -- cgit v1.2.3