summaryrefslogtreecommitdiffstats
path: root/acid
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-11-16 07:08:48 -0500
committerMalfurious <m@lfurio.us>2023-11-17 06:11:07 -0500
commitfdc21b961602843f8d1e24a7d772929f8c6032fc (patch)
tree41329729975299bc5a268c761351939dd6d450ed /acid
parentb1c95b10f4d1a0d49c2b888dcf10872b4a474569 (diff)
downloadcychedelic-fdc21b961602843f8d1e24a7d772929f8c6032fc.tar.gz
cychedelic-fdc21b961602843f8d1e24a7d772929f8c6032fc.zip
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 <m@lfurio.us>
Diffstat (limited to 'acid')
-rwxr-xr-xacid/acid-source19
1 files 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