From: Josh Rickmar Subject: Re: forbid rebase of references outside the refs/heads/ namespace To: gameoftrees@openbsd.org Date: Sat, 3 Sep 2022 17:01:14 -0400 On Sat, Sep 03, 2022 at 10:49:10PM +0200, Stefan Sperling wrote: > It does not seem useful to allow rebase of references outside the > "refs/heads/" namespace. Just like 'got commit' refuses to change > references outside of this namespace, 'got rebase' should refuse > to change them. > > ok? looks reasonable to me. besides references in refs/remotes (as tested in regress) i can't see this being at all good to use on refs/tags, refs/got, or anything else really. > > diff e72b098390333cd6d10b39518001fba7ba6a1790 6d141363b49d169a3918f862093595702c08d8a1 > commit - e72b098390333cd6d10b39518001fba7ba6a1790 > commit + 6d141363b49d169a3918f862093595702c08d8a1 > 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 > @@ -10228,6 +10228,12 @@ cmd_rebase(int argc, char *argv[]) > 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 > @@ -1656,6 +1656,33 @@ test_rebase_no_author_info() { > 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" > +} > + > test_parseargs "$@" > run_test test_rebase_basic > run_test test_rebase_ancestry_check > @@ -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 >