make 'got update' skip conflicted files ok millert@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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