Commit Diff


commit - dcf44d04283437bb25b602e26674f867e5b95f13
commit + 7d5807f4517a76c30cd479340f6968ca7eecce0b
blob - c9f01073d24211f7f8b682a6dd5ddb90ce9acbe9
blob + 1780abc217ffcc573874381bf38a884d642ed56e
--- got/got.1
+++ got/got.1
@@ -582,9 +582,13 @@ to a single base commit with
 If the work tree contains local changes, these changes must be committed
 or reverted first.
 .Pp
-Some
-.Nm
-commands may refuse to run while a rebase operation is in progress.
+The
+.Cm got update
+and
+.Cm got commit
+commands will refuse to run while a rebase operation is in progress.
+Other commands which manipulate the work tree may be used for
+conflict resolution purposes.
 .Pp
 The options for
 .Cm got rebase
blob - 93c26bfaf31797e96a848d1c39c3ddd5d3bde2d6
blob + d0fbca47f266147d83d4571d7efcff3c8c9cfbfb
--- got/got.c
+++ got/got.c
@@ -694,7 +694,7 @@ cmd_update(int argc, char *argv[])
 	char *commit_id_str = NULL;
 	const char *branch_name = NULL;
 	struct got_reference *head_ref = NULL;
-	int ch, did_something = 0;
+	int ch, did_something = 0, rebase_in_progress;
 
 	while ((ch = getopt(argc, argv, "b:c:")) != -1) {
 		switch (ch) {
@@ -726,8 +726,16 @@ cmd_update(int argc, char *argv[])
 		goto done;
 	}
 	error = got_worktree_open(&worktree, worktree_path);
+	if (error)
+		goto done;
+
+	error = got_worktree_rebase_in_progress(&rebase_in_progress, worktree);
 	if (error)
 		goto done;
+	if (rebase_in_progress) {
+		error = got_error(GOT_ERR_REBASING);
+		goto done;
+	}
 
 	if (argc == 0) {
 		path = strdup("");
@@ -2874,7 +2882,7 @@ cmd_commit(int argc, char *argv[])
 	const char *got_author = getenv("GOT_AUTHOR");
 	struct collect_commit_logmsg_arg cl_arg;
 	char *editor = NULL;
-	int ch;
+	int ch, rebase_in_progress;
 
 	while ((ch = getopt(argc, argv, "m:")) != -1) {
 		switch (ch) {
@@ -2912,8 +2920,16 @@ cmd_commit(int argc, char *argv[])
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
+	if (error)
+		goto done;
+
+	error = got_worktree_rebase_in_progress(&rebase_in_progress, worktree);
 	if (error)
+		goto done;
+	if (rebase_in_progress) {
+		error = got_error(GOT_ERR_REBASING);
 		goto done;
+	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
 	if (error != NULL)
blob - 441dea9a556adbeec96868da881ff0e40f1f605d
blob + 4a4ef0bdd9c32b7b02ae4cccbc6f721e54dfcc43
--- include/got_error.h
+++ include/got_error.h
@@ -101,6 +101,7 @@
 #define GOT_ERR_NOT_REBASING	85
 #define GOT_ERR_EMPTY_REBASE	86
 #define GOT_ERR_REBASE_COMMITID	87
+#define GOT_ERR_REBASING	88
 
 static const struct got_error {
 	int code;
@@ -198,6 +199,8 @@ static const struct got_error {
 	{ GOT_ERR_NOT_REBASING,	"rebase operation not in progress" },
 	{ GOT_ERR_EMPTY_REBASE,	"no commits to rebase" },
 	{ GOT_ERR_REBASE_COMMITID,"rebase commit ID mismatch" },
+	{ GOT_ERR_REBASING,	"a rebase operation is in progress in this "
+	    "work tree and must be continued or aborted first" },
 };
 
 /*
blob - 1ea60f6e05294029d697b0b612575092c927a2ef
blob + 91b9ba8be58e42753c9f676acbdaa9514e14bddb
--- regress/cmdline/rebase.sh
+++ regress/cmdline/rebase.sh
@@ -484,11 +484,108 @@ function test_rebase_no_op_change {
 	echo "commit $master_commit (master, newbranch)" \
 		> $testroot/stdout.expected
 	echo "commit $init_commit" >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_rebase_in_progress {
+	local testroot=`test_init rebase_no_op_change`
+	local init_commit=`git_show_head $testroot/repo`
+
+	(cd $testroot/repo && git checkout -q -b newbranch)
+	echo "modified alpha on branch" > $testroot/repo/alpha
+	git_commit $testroot/repo -m "committing to alpha on newbranch"
+	local orig_commit1=`git_show_head $testroot/repo`
+
+	(cd $testroot/repo && git checkout -q master)
+	echo "modified alpha on master" > $testroot/repo/alpha
+	git_commit $testroot/repo -m "committing to alpha on master"
+	local master_commit=`git_show_head $testroot/repo`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got rebase newbranch > $testroot/stdout \
+		2> $testroot/stderr)
+
+	echo "C  alpha" > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "got: conflicts must be resolved before rebase can be resumed" \
+		> $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
+	echo "modified alpha on branch" >> $testroot/content.expected
+	echo "=======" >> $testroot/content.expected
+	echo "modified alpha on master" >> $testroot/content.expected
+	echo '>>>>>>> alpha' >> $testroot/content.expected
+	cat $testroot/wt/alpha > $testroot/content
+	cmp -s $testroot/content.expected $testroot/content
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/content.expected $testroot/content
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo "C  alpha" > $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
 	fi
+
+	for cmd in update commit; do
+		(cd $testroot/wt && got $cmd > $testroot/stdout \
+			2> $testroot/stderr)
+
+		echo -n > $testroot/stdout.expected
+		cmp -s $testroot/stdout.expected $testroot/stdout
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stdout.expected $testroot/stdout
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+
+		echo -n "got: a rebase operation is in progress in this " \
+			> $testroot/stderr.expected
+		echo "work tree and must be continued or aborted first" \
+			>> $testroot/stderr.expected
+		cmp -s $testroot/stderr.expected $testroot/stderr
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stderr.expected $testroot/stderr
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+
 	test_done "$testroot" "$ret"
 }
 
@@ -497,3 +594,4 @@ run_test test_rebase_ancestry_check
 run_test test_rebase_continue
 run_test test_rebase_abort
 run_test test_rebase_no_op_change
+run_test test_rebase_in_progress