Commit 5036ab18bf99be5d6811f17565b2c2fad47b3f73

Stefan Sperling 2020-04-18T18:40:00

make 'got update' skip conflicted files ok millert@

diff --git a/got/got.1 b/got/got.1
index 6583cc3..a6a4b63 100644
--- a/got/got.1
+++ b/got/got.1
@@ -520,6 +520,18 @@ of this commit.
 Preserve any local changes in the work tree and merge them with the
 incoming changes.
 .Pp
+Files which already contain merge conflicts will not be updated to avoid
+further complications.
+Such files will be updated when
+.Cm got update
+is run again after merge conflicts have been resolved.
+If the conflicting changes are no longer needed affected files can be
+reverted with
+.Cm got revert
+before running
+.Cm got update
+again.
+.Pp
 Show the status of each affected file, using the following status codes:
 .Bl -column YXZ description
 .It U Ta file was updated and contained no local changes
@@ -529,6 +541,7 @@ Show the status of each affected file, using the following status codes:
 .It A Ta new file was added
 .It \(a~ Ta versioned file is obstructed by a non-regular file
 .It ! Ta a missing versioned file was restored
+.It # Ta file was not updated because it contains merge conflicts
 .El
 .Pp
 If no
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 7ee3eae..0dd838e 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -37,6 +37,7 @@ struct got_fileindex;
 #define GOT_STATUS_CANNOT_DELETE 'd'
 #define GOT_STATUS_BUMP_BASE	'b'
 #define GOT_STATUS_BASE_REF_ERR	'B'
+#define GOT_STATUS_CANNOT_UPDATE '#'
 
 /*
  * Attempt to initialize a new work tree on disk.
diff --git a/lib/worktree.c b/lib/worktree.c
index b4197e4..1ad69b7 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1303,6 +1303,11 @@ update_blob(struct got_worktree *worktree,
 		err = (*progress_cb)(progress_arg, status, path);
 		goto done;
 	}
+	if (status == GOT_STATUS_CONFLICT) {
+		err = (*progress_cb)(progress_arg, GOT_STATUS_CANNOT_UPDATE,
+		    path);
+		goto done;
+	}
 
 	if (ie && status != GOT_STATUS_MISSING &&
 	    (te->mode & S_IXUSR) == (sb.st_mode & S_IXUSR)) {
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 2225b5a..1df7e3d 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -1647,6 +1647,61 @@ function test_update_toggles_xbit {
 	test_done "$testroot" "$ret"
 }
 
+function test_update_preserves_conflicted_file {
+	local testroot=`test_init update_preserves_conflicted_file`
+	local commit_id0=`git_show_head $testroot/repo`
+
+	echo "modified alpha" > $testroot/repo/alpha
+	git_commit $testroot/repo -m "modified alpha"
+	local commit_id1=`git_show_head $testroot/repo`
+
+	got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# fake a merge conflict
+	echo '<<<<<<<' > $testroot/wt/alpha
+	echo 'alpha' >> $testroot/wt/alpha
+	echo '=======' >> $testroot/wt/alpha
+	echo 'alpha, too' >> $testroot/wt/alpha
+	echo '>>>>>>>' >> $testroot/wt/alpha
+	cp $testroot/wt/alpha $testroot/content.expected
+
+	echo "C  alpha" > $testroot/stdout.expected
+	(cd $testroot/wt && got status  > $testroot/stdout)
+	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 "#  alpha" > $testroot/stdout.expected
+	echo -n "Updated to commit " >> $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
+	(cd $testroot/wt && got update > $testroot/stdout)
+
+	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
+
+	cmp -s $testroot/content.expected $testroot/wt/alpha
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/content.expected $testroot/wt/alpha
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_update_basic
 run_test test_update_adds_file
 run_test test_update_deletes_file
@@ -1678,3 +1733,4 @@ run_test test_update_to_commit_on_wrong_branch
 run_test test_update_bumps_base_commit_id
 run_test test_update_tag
 run_test test_update_toggles_xbit
+run_test test_update_preserves_conflicted_file