commit 8dbcf3885ae920e0fd38a455e7577824989a605f from: Stefan Sperling via: Thomas Adam date: Sun Sep 04 11:18:30 2022 UTC forbid rebase of references outside the refs/heads/ namespace ok jrick commit - 35eabca99227d5245619972d35e5229c63c248db commit + 8dbcf3885ae920e0fd38a455e7577824989a605f blob - bdf06b70325f2720ec4a7f3bcdc35c740b1052f2 blob + 6cf8ccdbc08a98cb14efa193fceb1eb92fd05f97 --- got/got.1 +++ got/got.1 @@ -2144,6 +2144,11 @@ when the rebase operation continues. .Pp .Cm got rebase will refuse to run if certain preconditions are not met. +If the +.Ar branch +is not in the +.Dq refs/heads/ +reference namespace, the branch may not be rebased. If the work tree is not yet fully updated to the tip commit of its branch, then the work tree must first be updated with .Cm got update . blob - aca2d5adf35ad2c6712c336412f7a7312483a91b blob + fc35ac61061857e29979534c8c13565b1fc1e253 --- got/got.c +++ got/got.c @@ -10227,7 +10227,13 @@ cmd_rebase(int argc, char *argv[]) } else { error = got_ref_open(&branch, repo, argv[0], 0); if (error != NULL) + goto done; + if (strncmp(got_ref_get_name(branch), "refs/heads/", 11) != 0) { + error = got_error_msg(GOT_ERR_COMMIT_BRANCH, + "will not rebase a branch which lives outside " + "the \"refs/heads/\" reference namespace"); goto done; + } } error = got_ref_resolve(&branch_head_commit_id, repo, branch); blob - df770659022e0e33a3f45f53f5824326227836c9 blob + e25ace41e064b067ef0ead61dfe7efee5531dc25 --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1655,7 +1655,34 @@ test_rebase_no_author_info() { ret=$? if [ $ret -ne 0 ]; then diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +test_rebase_nonbranch() { + local testroot=`test_init rebase_nonbranch` + + got ref -r $testroot/repo -c refs/heads/master \ + refs/remotes/origin/master >/dev/null + + got checkout -b master $testroot/repo $testroot/wt >/dev/null + + (cd $testroot/wt && got rebase origin/master > $testroot/stdout \ + 2> $testroot/stderr) + ret=$? + if [ $ret -eq 0 ]; then + echo "rebase succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 fi + echo -n "got: will not rebase a branch which lives outside the " \ + > $testroot/stderr.expected + echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi test_done "$testroot" "$ret" } @@ -1676,3 +1703,4 @@ run_test test_rebase_delete_missing_file run_test test_rebase_rm_add_rm_file run_test test_rebase_resets_committer run_test test_rebase_no_author_info +run_test test_rebase_nonbranch