Commit fc6346c42a66d7fc562608e08dbd41e775facfc4

Stefan Sperling 2019-03-27T12:51:30

don't leave file as unversioned in case of wt edit vs repo rm

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="$?"