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:
@@ -7,7 +7,12 @@
|
||||
# DESCRIPTION
|
||||
# Prints the default remote-create command template for <type>, used by
|
||||
# mkrep's --server flow when $MKREP_REMOTE_CMD is unset. Same {name},
|
||||
# {user}, {server} placeholders as --new-remote.
|
||||
# {user}, {server} placeholders as --new-remote. gitlab/gitea guard
|
||||
# their final push on HEAD actually resolving to a commit -- mkrep only
|
||||
# ever runs `git init`, so a fresh call has no commit yet, and
|
||||
# `git push -u origin HEAD` errors on an unborn HEAD regardless of the
|
||||
# remote. Skipping the push there is silent success, not a swallowed
|
||||
# failure: once a commit exists, a real push failure still propagates.
|
||||
#
|
||||
# ARGUMENTS
|
||||
# type gitea, gitlab, or github
|
||||
@@ -23,9 +28,9 @@ function _mkrep_default_remote_cmd --argument-names type
|
||||
case github
|
||||
echo 'gh repo create {name} --private --source=. --remote=origin --push'
|
||||
case gitlab
|
||||
echo 'glab repo create {name} --private --skipGitInit && git remote add origin {server}/{user}/{name}.git && git push -u origin HEAD'
|
||||
echo 'glab repo create {name} --private --skipGitInit && git remote add origin {server}/{user}/{name}.git && if git rev-parse --verify -q HEAD >/dev/null 2>&1; git push -u origin HEAD; end'
|
||||
case gitea
|
||||
echo 'tea repos create --name {name} --private && git remote add origin {server}/{user}/{name}.git && git push -u origin HEAD'
|
||||
echo 'tea repos create --name {name} --private && git remote add origin {server}/{user}/{name}.git && if git rev-parse --verify -q HEAD >/dev/null 2>&1; git push -u origin HEAD; end'
|
||||
case '*'
|
||||
return 1
|
||||
end
|
||||
|
||||
+10
-7
@@ -104,14 +104,17 @@
|
||||
#
|
||||
# Starting points for $MKREP_REMOTE_CMD, one per host CLI -- each assumes
|
||||
# that tool is already installed and authenticated, creates a private
|
||||
# repo under the caller's own account, and pushes the initial commit.
|
||||
# These are also mkrep's built-in defaults for --server/$GIT_SERVER when
|
||||
# $MKREP_REMOTE_CMD is unset. gh supports a one-shot
|
||||
# --source/--remote/--push; glab and tea's create commands do not, so
|
||||
# they are chained with the git commands that do the linking:
|
||||
# repo under the caller's own account, and pushes it if there is
|
||||
# already a commit to push (mkrep itself only runs git init, so a
|
||||
# freshly created repo has none yet -- pushing an unborn HEAD is a
|
||||
# guaranteed error regardless of the remote, so the push is skipped
|
||||
# rather than attempted). These are also mkrep's built-in defaults for
|
||||
# --server/$GIT_SERVER when $MKREP_REMOTE_CMD is unset. gh supports a
|
||||
# one-shot --source/--remote/--push; glab and tea's create commands do
|
||||
# not, so they are chained with the git commands that do the linking:
|
||||
# GitHub (gh): gh repo create {name} --private --source=. --remote=origin --push
|
||||
# GitLab (glab): glab repo create {name} --private --skipGitInit && git remote add origin {server}/{user}/{name}.git && git push -u origin HEAD
|
||||
# Gitea (tea): tea repos create --name {name} --private && git remote add origin {server}/{user}/{name}.git && git push -u origin HEAD
|
||||
# GitLab (glab): glab repo create {name} --private --skipGitInit && git remote add origin {server}/{user}/{name}.git && if git rev-parse --verify -q HEAD >/dev/null 2>&1; git push -u origin HEAD; end
|
||||
# Gitea (tea): tea repos create --name {name} --private && git remote add origin {server}/{user}/{name}.git && if git rev-parse --verify -q HEAD >/dev/null 2>&1; git push -u origin HEAD; end
|
||||
function mkrep --description 'Create a directory, cd into it, and git init it'
|
||||
__fish_palette
|
||||
|
||||
|
||||
Reference in New Issue
Block a user