Commit Diff


commit - ceb466a7cccf5ed6424cd7e24839389a42e998c1
commit + 5036ab18bf99be5d6811f17565b2c2fad47b3f73
blob - 6583cc3872bc92bf71d69523894f2b671cdfb368
blob + a6a4b637e3612877e48634e1ee656fde08f4cce9
--- got/got.1
+++ 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 follo
 .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
blob - 7ee3eaeaa50ee972174740c861e33c472d33aa9a
blob + 0dd838e3937672354147a6c4cddeaadaa34de9c5
--- include/got_worktree.h
+++ 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.
blob - b4197e4d8c33edc1a60f7d33a519c558ed3726a8
blob + 1ad69b7dff719dd615ae921d1fc94b3ec3fabf39
--- lib/worktree.c
+++ 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)) {
blob - 2225b5ae82ab9273a4760df29891aa221c5898b3
blob + 1df7e3d7beccc4586b44046e8ad17ba462c564d9
--- regress/cmdline/update.sh
+++ regress/cmdline/update.sh
@@ -1643,7 +1643,62 @@ function test_update_toggles_xbit {
 	if [ "$ret" != "0" ]; then
 		echo "file is unexpectedly executable" >&2
 		ls -l $testroot/wt/xfile >&2
+	fi
+	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"
 }
 
@@ -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