Commit a0ea4fc07b81c69fa0409a2e39e702659f256179

Stefan Sperling 2020-02-28T17:37:53

show merged commit ID + logmsg upon merge conflict during rebase and histedit This makes it more apparent which commit contained the conflicting change. The new output looks like this: C sys/dev/pci/if_iwm.c 8a98d848a1a5 -> merge conflict: properly modify station queues got: conflicts must be resolved before rebasing can continue

diff --git a/got/got.c b/got/got.c
index bae230a..021418d 100644
--- a/got/got.c
+++ b/got/got.c
@@ -5139,6 +5139,35 @@ done:
 }
 
 static const struct got_error *
+show_rebase_merge_conflict(struct got_object_id *id, struct got_repository *repo)
+{
+	const struct got_error *err;
+	struct got_commit_object *commit = NULL;
+	char *id_str = NULL, *logmsg = NULL;
+
+	err = got_object_open_as_commit(&commit, repo, id);
+	if (err)
+		return err;
+
+	err = got_object_id_str(&id_str, id);
+	if (err)
+		goto done;
+
+	id_str[12] = '\0';
+
+	err = get_short_logmsg(&logmsg, 42, commit);
+	if (err)
+		goto done;
+
+	printf("%s -> merge conflict: %s\n", id_str, logmsg);
+done:
+	free(id_str);
+	got_object_commit_close(commit);
+	free(logmsg);
+	return err;
+}
+
+static const struct got_error *
 show_rebase_progress(struct got_commit_object *commit,
     struct got_object_id *old_id, struct got_object_id *new_id)
 {
@@ -5586,6 +5615,9 @@ cmd_rebase(int argc, char *argv[])
 			goto done;
 
 		if (rebase_status == GOT_STATUS_CONFLICT) {
+			error = show_rebase_merge_conflict(qid->id, repo);
+			if (error)
+				goto done;
 			got_worktree_rebase_pathlist_free(&merged_paths);
 			break;
 		}
@@ -6761,6 +6793,10 @@ cmd_histedit(int argc, char *argv[])
 		commit = NULL;
 
 		if (rebase_status == GOT_STATUS_CONFLICT) {
+			error = show_rebase_merge_conflict(hle->commit_id,
+			    repo);
+			if (error)
+				goto done;
 			got_worktree_rebase_pathlist_free(&merged_paths);
 			break;
 		}
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index 0537513..262922a 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -182,6 +182,7 @@ function test_rebase_continue {
 	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`
+	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
 
 	(cd $testroot/repo && git checkout -q master)
 	echo "modified alpha on master" > $testroot/repo/alpha
@@ -199,6 +200,9 @@ function test_rebase_continue {
 		2> $testroot/stderr)
 
 	echo "C  alpha" > $testroot/stdout.expected
+	echo -n "$short_orig_commit1 -> merge conflict" \
+		>> $testroot/stdout.expected
+	echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
@@ -276,8 +280,6 @@ function test_rebase_continue {
 
 	(cd $testroot/repo && git checkout -q newbranch)
 	local new_commit1=`git_show_head $testroot/repo`
-
-	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
 	local short_new_commit1=`trim_obj_id 28 $new_commit1`
 
 	echo -n "$short_orig_commit1 -> $short_new_commit1" \
@@ -315,6 +317,7 @@ function test_rebase_abort {
 	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`
+	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
 
 	(cd $testroot/repo && git checkout -q master)
 	echo "modified alpha on master" > $testroot/repo/alpha
@@ -332,6 +335,9 @@ function test_rebase_abort {
 		2> $testroot/stderr)
 
 	echo "C  alpha" > $testroot/stdout.expected
+	echo -n "$short_orig_commit1 -> merge conflict" \
+		>> $testroot/stdout.expected
+	echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
@@ -427,6 +433,7 @@ function test_rebase_no_op_change {
 	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`
+	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
 
 	(cd $testroot/repo && git checkout -q master)
 	echo "modified alpha on master" > $testroot/repo/alpha
@@ -444,6 +451,9 @@ function test_rebase_no_op_change {
 		2> $testroot/stderr)
 
 	echo "C  alpha" > $testroot/stdout.expected
+	echo -n "$short_orig_commit1 -> merge conflict" \
+		>> $testroot/stdout.expected
+	echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
@@ -499,8 +509,6 @@ function test_rebase_no_op_change {
 	(cd $testroot/repo && git checkout -q newbranch)
 	local new_commit1=`git_show_head $testroot/repo`
 
-	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
-
 	echo -n "$short_orig_commit1 -> no-op change" \
 		> $testroot/stdout.expected
 	echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
@@ -536,6 +544,7 @@ function test_rebase_in_progress {
 	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`
+	local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
 
 	(cd $testroot/repo && git checkout -q master)
 	echo "modified alpha on master" > $testroot/repo/alpha
@@ -553,6 +562,9 @@ function test_rebase_in_progress {
 		2> $testroot/stderr)
 
 	echo "C  alpha" > $testroot/stdout.expected
+	echo -n "$short_orig_commit1 -> merge conflict" \
+		>> $testroot/stdout.expected
+	echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then