commit 442ede73eadb025cdc45bede186bf31aee869dad from: Stefan Sperling date: Sun Sep 04 06:42:40 2022 UTC forbid rebase of references outside the refs/heads/ namespace ok jrick commit - b68bd9d2b487fd0020818848e9c8ac955e5570fd commit + 442ede73eadb025cdc45bede186bf31aee869dad 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 - 64ef5fc0ef4b1bd3dce557f8ecb20c5f2946dee6 blob + e8369725fe5afccaf92cac20559a3594304240bd --- 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 - b2315194a6347d2b00b98f019861b2b6776d08ef blob + 59b9d0cacb742bc1bd8bb4c444a37d5f22de820a --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1652,7 +1652,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" } @@ -1673,3 +1700,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