commit 9a1ea1d6e6dffd7c10000689a43ff7c285e4e023d4801696a8850490df68eb5b from: Stefan Sperling date: Fri Feb 20 14:01:39 2026 UTC make gotadmin cleanup run even if the HEAD ref points at a non-existent branch ok op@ commit - c13c75b17c0c3e979eb177d89481b58f1221f0a39892092cbef99f04e22baad4 commit + 9a1ea1d6e6dffd7c10000689a43ff7c285e4e023d4801696a8850490df68eb5b blob - e0228b121feef2b3e689bf5cc8975b40cfa264c086d6f5876624413355b46ddc blob + 4b62391d8f00358e7ec79bba8e711847943a89964fd3874104dadfc0988a5f4d --- lib/reference.c +++ lib/reference.c @@ -678,8 +678,11 @@ get_committer_time(struct got_reference *ref, struct g struct got_object_id *id = NULL; err = got_ref_resolve(&id, repo, ref); - if (err) + if (err) { + if (err->code == GOT_ERR_NOT_REF && got_ref_is_symbolic(ref)) + return NULL; return err; + } err = got_object_get_type(&obj_type, repo, id); if (err) blob - ffcccf1028e9c835c73b1651642b9e5e3c3f3a6e990d7b4d544b49a3d92d363f blob + 30289592c84fb9ca3032a3606d0e230ee71a5da39c0d8f84eedd44028f9e3807 --- lib/repository_admin.c +++ lib/repository_admin.c @@ -96,8 +96,14 @@ get_reflist_object_ids(struct got_object_id ***ids, in } err = got_ref_resolve(&id, repo, re->ref); - if (err) + if (err) { + if (err->code == GOT_ERR_NOT_REF && + got_ref_is_symbolic(re->ref)) { + err = NULL; + continue; + } goto done; + } if (wanted_obj_type_mask != GOT_OBJ_TYPE_ANY) { int obj_type; blob - 3e9ba7049ef967a632e09aa7769d1c0feac574264f9113b16623753061d6c467 blob + d3fc5ec766d39fe6b4d5f6e876d1055f87eac3b3a92accacd919f51d7203a276 --- regress/cmdline/cleanup.sh +++ regress/cmdline/cleanup.sh @@ -694,6 +694,41 @@ EOF test_done "$testroot" "$ret" } +test_cleanup_no_head_branch() { + local testroot=`test_init cleanup_no_head_branch` + local commit_id=`git_show_head $testroot/repo` + + # create a dangling HEAD reference + echo 'ref: refs/heads/main' > $testroot/repo/.git/HEAD + + # list references + got ref -r $testroot/repo -l > $testroot/stdout + cat > $testroot/stdout.expected < $testroot/stdout \ + 2> $testroot/stderr + ret=$? + if [ $ret -ne 0 ]; then + echo "gotadmin cleanup failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_cleanup_unreferenced_loose_objects run_test test_cleanup_redundant_loose_objects @@ -701,3 +736,4 @@ run_test test_cleanup_redundant_pack_files run_test test_cleanup_precious_objects run_test test_cleanup_missing_pack_file run_test test_cleanup_non_commit_ref +run_test test_cleanup_no_head_branch