don't leave file as unversioned in case of wt edit vs repo rm
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
diff --git a/lib/worktree.c b/lib/worktree.c
index 3f0523f..694339a 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1219,7 +1219,7 @@ delete_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
got_worktree_checkout_cb progress_cb, void *progress_arg,
got_worktree_cancel_cb cancel_cb, void *cancel_arg)
{
- const struct got_error *err;
+ const struct got_error *err = NULL;
unsigned char status;
struct stat sb;
char *ondisk_path;
@@ -1232,16 +1232,28 @@ delete_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
if (err)
return err;
- (*progress_cb)(progress_arg, GOT_STATUS_DELETE, ie->path);
-
- if (status == GOT_STATUS_NO_CHANGE) {
- err = remove_ondisk_file(worktree->root_path, ie->path);
+ if (status == GOT_STATUS_MODIFY || status == GOT_STATUS_CONFLICT ||
+ status == GOT_STATUS_ADD) {
+ (*progress_cb)(progress_arg, GOT_STATUS_MERGE, ie->path);
+ /*
+ * Preserve the working file and change the deleted blob's
+ * entry into a schedule-add entry.
+ */
+ err = got_fileindex_entry_update(ie, ondisk_path, NULL, NULL,
+ 0);
if (err)
return err;
+ } else {
+ (*progress_cb)(progress_arg, GOT_STATUS_DELETE, ie->path);
+ if (status == GOT_STATUS_NO_CHANGE) {
+ err = remove_ondisk_file(worktree->root_path, ie->path);
+ if (err)
+ return err;
+ }
+ got_fileindex_entry_remove(fileindex, ie);
}
- got_fileindex_entry_remove(fileindex, ie);
- return NULL;
+ return err;
}
struct diff_cb_arg {
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 5b27ea3..f5e6128 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -926,7 +926,7 @@ function test_update_conflict_wt_edit_vs_repo_rm {
(cd $testroot/wt && got update > $testroot/stdout)
- echo "D beta" > $testroot/stdout.expected
+ echo "G beta" > $testroot/stdout.expected
echo -n "Updated to commit " >> $testroot/stdout.expected
git_show_head $testroot/repo >> $testroot/stdout.expected
echo >> $testroot/stdout.expected
@@ -950,8 +950,8 @@ function test_update_conflict_wt_edit_vs_repo_rm {
return 1
fi
- # beta is now an unversioned file... we don't flag tree conflicts yet
- echo '? beta' > $testroot/stdout.expected
+ # beta is now an added file... we don't flag tree conflicts yet
+ echo 'A beta' > $testroot/stdout.expected
(cd $testroot/wt && got status > $testroot/stdout)
cmp $testroot/stdout.expected $testroot/stdout
ret="$?"