fix(git): don't push an unborn HEAD from mkrep's default remote templates

mkrep only ever runs git init, never a commit, so a freshly created
repo has no HEAD yet. The gitea/gitlab default templates chained
`git push -u origin HEAD` unconditionally after linking the remote,
which fails immediately regardless of the remote ("src refspec HEAD
does not match any") -- reproduced by a real user hitting it on the
first mkrep --server call. Guard the push on HEAD actually resolving
to a commit; skipping it is the correct outcome (nothing to push yet),
and a real push failure once a commit exists still propagates.
This commit is contained in:
2026-09-14 23:22:52 -04:00
parent 0a3b332d79
commit 17721a1cf2
3 changed files with 40 additions and 10 deletions
+22
View File
@@ -255,6 +255,28 @@ function _mkrep_stub_tool --argument-names name exit_code
chmod +x $stub_bin/$name
end
section "mkrep: --server's default gitea template survives an empty (commit-less) repo"
begin
# Regression: mkrep only ever runs `git init`, so a freshly created
# repo has no commits yet. The default template's final push must not
# error on that unborn HEAD once `tea repos create` and `git remote
# add` (both real, local-only) have already succeeded.
printf '#!/bin/sh\ncase "$2" in\n create) exit 0 ;;\n *) exit 1 ;;\nesac\n' >$stub_bin/tea
chmod +x $stub_bin/tea
set -l base (_mkrep_sandbox)
set -l target $base/repo
set -lx PATH $stub_bin $PATH
set -lx GITEA_URL https://gitea.example.invalid
set -lx MKREP_REMOTE_CMD ''
mkrep --server gitea $target >/dev/null
check "default template exits 0 with no commits yet" 0 $status
set -l url (git -C $target remote get-url origin)
check "default template still linked the new remote" "https://gitea.example.invalid/$USER/repo.git" $url
cd $start
rm -rf $base
end
section "mkrep: --server auto-creates when the repo does not exist"
begin