commit 885707edec53f628c3039c20031c89670d36d2f6 from: Josh Rickmar via: Thomas Adam date: Tue Sep 27 14:55:40 2022 UTC disallow integrating into references outside refs/heads/ Spotted by stsp@ while considering a feature request for cmd_integrate. ok stsp@ commit - 529beb87076bdd7e139b49203080f45e70cfcc09 commit + 885707edec53f628c3039c20031c89670d36d2f6 blob - aa4a411ffcd6b1548c7dd705448a655602514913 blob + f95acae454f160625ff566ed5baf5f71728d82d0 --- got/got.c +++ got/got.c @@ -11957,6 +11957,12 @@ cmd_integrate(int argc, char *argv[]) base_refname = strdup(got_ref_get_name(base_branch_ref)); if (base_refname == NULL) { error = got_error_from_errno("strdup"); + got_worktree_integrate_abort(worktree, fileindex, repo, + branch_ref, base_branch_ref); + goto done; + } + if (strncmp(base_refname, "refs/heads/", 11) != 0) { + error = got_error(GOT_ERR_INTEGRATE_BRANCH); got_worktree_integrate_abort(worktree, fileindex, repo, branch_ref, base_branch_ref); goto done; blob - 32ded08f2703834a744542900c736972cdb203ad blob + cce0d33fcbab7eccd18295fbaf62878872bb9369 --- include/got_error.h +++ include/got_error.h @@ -176,6 +176,7 @@ #define GOT_ERR_SIGNING_TAG 156 #define GOT_ERR_COMMIT_REDUNDANT_AUTHOR 157 #define GOT_ERR_BAD_QUERYSTRING 158 +#define GOT_ERR_INTEGRATE_BRANCH 159 struct got_error { int code; blob - bd09c98f60e847f0f4694f3931012a07cce40577 blob + b9fcb53fd688103beb1de6a8ced2f6aecdba2b14 --- lib/error.c +++ lib/error.c @@ -231,6 +231,8 @@ static const struct got_error got_errors[] = { { GOT_ERR_COMMIT_REDUNDANT_AUTHOR, "specified author is equal to the " "default one"}, { GOT_ERR_BAD_QUERYSTRING, "invalid query string" }, + { GOT_ERR_INTEGRATE_BRANCH, "will not integrate into a reference " + "outside the \"refs/heads/\" reference namespace" }, }; static struct got_custom_error { blob - 8c528ea1f5a368de063e916a5668b66b65392105 blob + a4561e55b71ef739aea26419efa37a02818e8885 --- regress/cmdline/integrate.sh +++ regress/cmdline/integrate.sh @@ -495,7 +495,52 @@ test_integrate_replace_file_with_symlink() { ret=$? if [ $ret -ne 0 ]; then diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +test_integrate_into_nonbranch() { + local testroot=`test_init test_integrate_into_nonbranch` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "checkout failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + local commit=`git_show_head $testroot/repo` + (cd $testroot/repo && got ref -c $commit refs/remotes/origin/master) + + echo "modified alpha on branch" > $testroot/repo/alpha + git_commit $testroot/repo -m "committing to alpha on master" + + (cd $testroot/wt && got up -b origin/master > /dev/null) + ret=$? + if [ $ret -ne 0 ]; then + echo "got branch failed unexpectedly" + test_done "$testroot" "$ret" + return 1 fi + + (cd $testroot/wt && got integrate master \ + > $testroot/stdout 2> $testroot/stderr) + ret=$? + if [ $ret -eq 0 ]; then + echo "got integrate succeeded unexpectedly" + test_done "$testroot" "$ret" + return 1 + fi + + echo -n "got: will not integrate into a reference 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" } @@ -506,3 +551,4 @@ run_test test_integrate_path_prefix run_test test_integrate_backwards_in_time run_test test_integrate_replace_symlink_with_file run_test test_integrate_replace_file_with_symlink +run_test test_integrate_into_nonbranch