From 0a3b332d794c24ebdcb80d9f70b628cc8f3c329b Mon Sep 17 00:00:00 2001 From: Rootiest Date: Mon, 14 Sep 2026 23:11:12 -0400 Subject: [PATCH] fix(git): prepend https:// to *_HOST vars in mkrep server detection $GITEA_HOST/$GITLAB_HOST are bare hostnames (git.example.com); only $GITEA_URL/$GITLAB_URL are expected to carry a scheme. mkrep was using _HOST values as-is, producing a schemeless clone URL when only the _HOST var was set. --- functions/mkrep.fish | 8 +++++--- tests/test-mkrep.fish | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/functions/mkrep.fish b/functions/mkrep.fish index 06b0b74..b9f638a 100644 --- a/functions/mkrep.fish +++ b/functions/mkrep.fish @@ -42,7 +42,9 @@ # --server (gitea, gitlab, or github) picks a host without an # explicit --remote/--new-remote: resolve its base URL from # $GITEA_URL/$GITEA_HOST (gitea) or $GITLAB_URL/$GITLAB_HOST (gitlab), -# preferring the _URL form when both are set, then run +# preferring the _URL form when both are set. _URL is used as-is and +# must include its scheme (https://git.example.com); _HOST is bare +# (git.example.com) and gets https:// prepended. Then run # $MKREP_REMOTE_CMD or that type's built-in default template. With no # --server, --remote, or --new-remote, $GIT_SERVER picks the type the # same way (invalid values are rejected the same as an invalid @@ -195,13 +197,13 @@ function mkrep --description 'Create a directory, cd into it, and git init it' if test -n "$GITEA_URL" set srv_url $GITEA_URL else if test -n "$GITEA_HOST" - set srv_url $GITEA_HOST + set srv_url "https://$GITEA_HOST" end case gitlab if test -n "$GITLAB_URL" set srv_url $GITLAB_URL else if test -n "$GITLAB_HOST" - set srv_url $GITLAB_HOST + set srv_url "https://$GITLAB_HOST" end case github # gh defaults to github.com; no base url needed diff --git a/tests/test-mkrep.fish b/tests/test-mkrep.fish index d863688..6b9a570 100644 --- a/tests/test-mkrep.fish +++ b/tests/test-mkrep.fish @@ -289,6 +289,38 @@ begin rm -rf $base end +section "mkrep: \$GITEA_HOST gets https:// prepended, \$GITEA_URL wins over it" + +begin + _mkrep_stub_tool tea 1 + set -l base (_mkrep_sandbox) + set -l target $base/repo + set -lx PATH $stub_bin $PATH + set -lx GITEA_URL '' + set -lx GITEA_HOST gitea.example.invalid + set -lx MKREP_REMOTE_CMD 'echo {server} >created.txt' + mkrep --server gitea $target >/dev/null + check "bare \$GITEA_HOST exits 0" 0 $status + check "bare \$GITEA_HOST gets https:// prepended" https://gitea.example.invalid (cat $target/created.txt) + cd $start + rm -rf $base +end + +begin + _mkrep_stub_tool tea 1 + set -l base (_mkrep_sandbox) + set -l target $base/repo + set -lx PATH $stub_bin $PATH + set -lx GITEA_HOST wrong.example.invalid + set -lx GITEA_URL https://right.example.invalid + set -lx MKREP_REMOTE_CMD 'echo {server} >created.txt' + mkrep --server gitea $target >/dev/null + check "\$GITEA_URL wins over \$GITEA_HOST exits 0" 0 $status + check "\$GITEA_URL wins over \$GITEA_HOST, used as-is" https://right.example.invalid (cat $target/created.txt) + cd $start + rm -rf $base +end + section "mkrep: \$GITEA_URL alone (no \$GIT_SERVER) does not trigger anything" begin