fix a bug where files skipped by 'got update' could not be updated again ok semarie@
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
diff --git a/lib/fileindex.c b/lib/fileindex.c
index d1e3839..aec06af 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -46,6 +46,7 @@
#define GOT_FILEIDX_F_NO_COMMIT 0x00040000
#define GOT_FILEIDX_F_NO_FILE_ON_DISK 0x00080000
#define GOT_FILEIDX_F_REMOVE_ON_FLUSH 0x00100000
+#define GOT_FILEIDX_F_SKIPPED 0x00200000
struct got_fileindex {
struct got_fileindex_tree entries;
@@ -146,6 +147,12 @@ got_fileindex_entry_mark_deleted_from_disk(struct got_fileindex_entry *ie)
ie->flags |= GOT_FILEIDX_F_NO_FILE_ON_DISK;
}
+void
+got_fileindex_entry_mark_skipped(struct got_fileindex_entry *ie)
+{
+ ie->flags |= GOT_FILEIDX_F_SKIPPED;
+}
+
const struct got_error *
got_fileindex_entry_alloc(struct got_fileindex_entry **ie,
const char *relpath)
@@ -245,6 +252,12 @@ got_fileindex_entry_has_file_on_disk(struct got_fileindex_entry *ie)
return (ie->flags & GOT_FILEIDX_F_NO_FILE_ON_DISK) == 0;
}
+int
+got_fileindex_entry_was_skipped(struct got_fileindex_entry *ie)
+{
+ return (ie->flags & GOT_FILEIDX_F_SKIPPED) != 0;
+}
+
static const struct got_error *
add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
{
@@ -497,6 +510,7 @@ got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
RB_FOREACH_SAFE(ie, got_fileindex_tree, &fileindex->entries, tmp) {
ie->flags &= ~GOT_FILEIDX_F_NOT_FLUSHED;
+ ie->flags &= ~GOT_FILEIDX_F_SKIPPED;
if (ie->flags & GOT_FILEIDX_F_REMOVE_ON_FLUSH) {
RB_REMOVE(got_fileindex_tree, &fileindex->entries, ie);
got_fileindex_entry_free(ie);
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index 537374d..d03058e 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -109,6 +109,7 @@ mode_t got_fileindex_perms_to_st(struct got_fileindex_entry *);
const struct got_error *got_fileindex_entry_update(struct got_fileindex_entry *,
int, const char *, uint8_t *, uint8_t *, int);
+void got_fileindex_entry_mark_skipped(struct got_fileindex_entry *);
const struct got_error *got_fileindex_entry_alloc(struct got_fileindex_entry **,
const char *);
void got_fileindex_entry_free(struct got_fileindex_entry *);
@@ -164,6 +165,7 @@ const struct got_error *got_fileindex_diff_dir(struct got_fileindex *, int,
int got_fileindex_entry_has_blob(struct got_fileindex_entry *);
int got_fileindex_entry_has_commit(struct got_fileindex_entry *);
int got_fileindex_entry_has_file_on_disk(struct got_fileindex_entry *);
+int got_fileindex_entry_was_skipped(struct got_fileindex_entry *);
uint32_t got_fileindex_entry_stage_get(const struct got_fileindex_entry *);
void got_fileindex_entry_stage_set(struct got_fileindex_entry *ie, uint32_t);
int got_fileindex_entry_filetype_get(struct got_fileindex_entry *);
diff --git a/lib/worktree.c b/lib/worktree.c
index 57631f3..9cc4b32 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1951,6 +1951,8 @@ update_blob(struct got_worktree *worktree,
goto done;
}
if (status == GOT_STATUS_CONFLICT) {
+ if (ie)
+ got_fileindex_entry_mark_skipped(ie);
err = (*progress_cb)(progress_arg, GOT_STATUS_CANNOT_UPDATE,
path);
goto done;
@@ -2474,6 +2476,9 @@ bump_base_commit_id(void *arg, struct got_fileindex_entry *ie)
} else if (!got_path_is_child(ie->path, a->path, a->path_len))
return NULL;
+ if (got_fileindex_entry_was_skipped(ie))
+ return NULL;
+
if (memcmp(ie->commit_sha1, a->base_commit_id->sha1,
SHA1_DIGEST_LENGTH) == 0)
return NULL;
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index fa03988..1869166 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -2391,6 +2391,187 @@ test_update_single_file() {
return 0
}
+test_update_file_skipped_due_to_conflict() {
+ local testroot=`test_init update_file_skipped_due_to_conflict`
+ local commit_id0=`git_show_head $testroot/repo`
+ blob_id0=`get_blob_id $testroot/repo "" beta`
+
+ echo "changed beta" > $testroot/repo/beta
+ git_commit $testroot/repo -m "changed beta"
+ local commit_id1=`git_show_head $testroot/repo`
+ blob_id1=`get_blob_id $testroot/repo "" beta`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
+ cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$blob_id" != "$blob_id1" ]; then
+ echo "file beta has the wrong base blob ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ commit_id=`(cd $testroot/wt && got info beta | \
+ grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$commit_id" != "$commit_id1" ]; then
+ echo "file beta has the wrong base commit ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "modified beta" > $testroot/wt/beta
+
+ (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
+
+ echo "C beta" > $testroot/stdout.expected
+ echo "Updated to commit $commit_id0" >> $testroot/stdout.expected
+ echo "Files with new merge conflicts: 1" >> $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 "<<<<<<< merged change: commit $commit_id0" \
+ > $testroot/content.expected
+ echo "beta" >> $testroot/content.expected
+ echo "||||||| 3-way merge base: commit $commit_id1" \
+ >> $testroot/content.expected
+ echo "changed beta" >> $testroot/content.expected
+ echo "=======" >> $testroot/content.expected
+ echo "modified beta" >> $testroot/content.expected
+ echo ">>>>>>>" >> $testroot/content.expected
+
+ cat $testroot/wt/beta > $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
+
+ blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
+ cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$blob_id" != "$blob_id0" ]; then
+ echo "file beta has the wrong base blob ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ commit_id=`(cd $testroot/wt && got info beta | \
+ grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$commit_id" != "$commit_id0" ]; then
+ echo "file beta has the wrong base commit ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ # update to the latest commit again; this skips beta
+ (cd $testroot/wt && got update > $testroot/stdout)
+ echo "# beta" > $testroot/stdout.expected
+ echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
+ echo "Files not updated because of existing merge conflicts: 1" \
+ >> $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
+
+ # blob ID of beta should not have changed
+ blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
+ cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$blob_id" != "$blob_id0" ]; then
+ echo "file beta has the wrong base blob ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ # commit ID of beta should not have changed; There was a bug
+ # here where the commit ID had been changed even though the
+ # file was not updated.
+ commit_id=`(cd $testroot/wt && got info beta | \
+ grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$commit_id" != "$commit_id0" ]; then
+ echo "file beta has the wrong base commit ID: $commit_id" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ # beta is still conflicted and based on commit 0
+ echo 'C beta' > $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
+
+ # resolve the conflict via revert
+ (cd $testroot/wt && got revert beta >/dev/null)
+
+ # beta now matches its base blob which is still from commit 0
+ echo "beta" > $testroot/content.expected
+ cat $testroot/wt/beta > $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
+
+ # updating to the latest commit should now update beta
+ (cd $testroot/wt && got update > $testroot/stdout)
+ echo "U beta" > $testroot/stdout.expected
+ echo "Updated to commit $commit_id1" >> $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
+
+ blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
+ cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$blob_id" != "$blob_id1" ]; then
+ echo "file beta has the wrong base blob ID" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ commit_id=`(cd $testroot/wt && got info beta | \
+ grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
+ if [ "$commit_id" != "$commit_id1" ]; then
+ echo "file beta has the wrong base commit ID: $commit_id" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "changed beta" > $testroot/content.expected
+ cat $testroot/wt/beta > $testroot/content
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ fi
+ test_done "$testroot" "$ret"
+}
+
test_parseargs "$@"
run_test test_update_basic
@@ -2432,3 +2613,4 @@ run_test test_update_adds_symlink
run_test test_update_deletes_symlink
run_test test_update_symlink_conflicts
run_test test_update_single_file
+run_test test_update_file_skipped_due_to_conflict