Commit Diff


commit - e02bf8ada9fce6518a7ad40401425a26bdaadbb4
commit + e02b422b6f7736de0e851b3f8fad812e77e9c6b4
blob - 04f6245bfb7bfdc492c4818321900ff49e579289
blob + 2fe9e120a0bace5a7b80643b8da00a79f1462de8
--- 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 - 81dce95fb636e4a9cb9a660616f6048f8403eb14
blob + 3ef43e397f0c76093e7db235561aa095240895e8
--- include/got_error.h
+++ include/got_error.h
@@ -174,6 +174,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 - 711554564cdd65bb927ad7bc3bebbbc253efd6ac
blob + c723f568d0bd96f1f5426bbe92a5ff499bad92f6
--- lib/error.c
+++ lib/error.c
@@ -223,6 +223,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