commit 5bf64361d0703410f1b9ff9479cb21f0d384bc26d8b3f5f6531a419dcb842c2b from: Stefan Sperling date: Wed Feb 4 13:05:29 2026 UTC fix setting of a custom HEAD reference during repository creation by gotsysd A parameter of got_repo_init() is supposed to be a branch name but gotsys-repo-create was passing an absolute reference name instead. This resulted in problems like refs/heads/refs/heads/foo being set as HEAD. Add test coverage for this issue. A workaround exists: Affected repositories are repaired as soon as another gotsys.conf change is committed or 'gotsys apply' is triggered manually. commit - c79455a620d8715b522d961f3c5681f295dd6e95b9224fa9e7fc2bc84909ade2 commit + 5bf64361d0703410f1b9ff9479cb21f0d384bc26d8b3f5f6531a419dcb842c2b blob - ec920b98d174cbc13a35613d024ba6b6b2e680b76a9df11aa7e4f6e368c3f7ce blob + 32e8d4676bf4705cdb24ee5bdce59cf0439db900e00cbe465c2cf87ffb8c52cb --- gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c +++ gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c @@ -212,6 +212,7 @@ create_repo(struct imsg *imsg) struct gotsysd_imsg_sysconf_repo_create param; char *repo_name = NULL; char *headref = NULL; + const char *head_name = NULL; char *fullname = NULL; char *abspath = NULL; @@ -250,6 +251,10 @@ create_repo(struct imsg *imsg) err = got_error_path(headref, GOT_ERR_BAD_REF_NAME); goto done; } + + head_name = headref; + if (strncmp(head_name, "refs/heads/", 11) == 0) + head_name += 11; } err = gotsys_conf_validate_repo_name(repo_name); @@ -286,7 +291,7 @@ create_repo(struct imsg *imsg) } else err = got_error_from_errno2("mkdir", abspath); } else - err = got_repo_init(abspath, headref, GOT_HASH_SHA1); + err = got_repo_init(abspath, head_name, GOT_HASH_SHA1); done: free(repo_name); free(fullname); blob - 2b7eaf23954cae257e1cefb9a24b9046be1f4e00e4b0886b89f6e6ba4c7136a4 blob + c16bcbba5de8b043aec84f895cf16aa67954bf4799919700523e3fc0dbfdc42b --- regress/gotsysd/test_gotsysd.sh +++ regress/gotsysd/test_gotsysd.sh @@ -1432,6 +1432,11 @@ repository "foo" { permit ro anonymous head foo } +repository "customhead" { + permit rw ${GOTSYSD_DEV_USER} + permit ro anonymous + head foo +} EOF (cd ${testroot}/wt && got commit -m "set foo as head" >/dev/null) local commit_id=`git_show_head $testroot/${GOTSYS_REPO}` @@ -1476,9 +1481,70 @@ EOF # The foo repository should now advertise refs/heads/foo as HEAD. got clone -q -l anonymous@${VMIP}:foo.git | egrep '^HEAD:' \ + > $testroot/stdout + echo "HEAD: refs/heads/foo" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + ssh -i ${GOTSYSD_SSH_KEY} root@${VMIP} cat /git/customhead.git/HEAD \ > $testroot/stdout + echo "ref: refs/heads/foo" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout ret=$? if [ $ret -ne 0 ]; then + echo "wrong HEAD ref set during repository creation" >&2 + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Forcibly apply the configuration again. HEAD refs will be updated + # and should remain unchanged. + ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} 'gotsys apply -w' > /dev/null + + ssh -i ${GOTSYSD_SSH_KEY} root@${VMIP} cat /git/customhead.git/HEAD \ + > $testroot/stdout + echo "ref: refs/heads/foo" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "wrong HEAD ref after gotsys apply" >&2 + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Create branch "foo" in customhead.git. + got init -b foo $testroot/customhead.git + mkdir $testroot/foo + echo alpha > $testroot/foo/alpha + got import -m init -b foo -r $testroot/customhead.git \ + $testroot/foo >/dev/null + cat > $testroot/customhead.git/got.conf <&2 + return 1 + fi + + # The customhead repository should now advertise refs/heads/foo as HEAD. + got clone -q -l anonymous@${VMIP}:customhead.git | egrep '^HEAD:' \ + > $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then echo "got clone -l failed unexpectedly" >&2 test_done "$testroot" 1 return 1