git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.

From
Mikhail Filippov <mikhail@filippov.me>
Date
Sep 11, 2016, 20:25 UTC
Message-ID
<1473625505-7641-1-git-send-email-mikhail@filippov.me>
---
 merge-recursive.c                    |  9 +++++---
 t/t6042-merge-rename-corner-cases.sh | 42 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index e349126..25dc701 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
 		 */
 		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
 		if (!path_renamed_outside_HEAD) {
-			add_cacheinfo(o, mfi.mode, &mfi.oid, path,
-				      0, (!o->call_depth), 0);
-			return mfi.clean;
+			struct stat st;
+			if (lstat(path, &st) == 0) {
+				add_cacheinfo(o, mfi.mode, &mfi.oid, path,
+					      0, (!o->call_depth), 0);
+				return mfi.clean;
+			}
 		}
 	} else
 		output(o, 2, _("Auto-merging %s"), path);
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index 411550d..2073e49 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -575,4 +575,46 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
 	test ! -f c
 '
 
+test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	echo output >.gitignore &&
+	echo .gitignore >>.gitignore &&
+
+	echo b1 >b1 &&
+	git add b1 &&
+	git commit -m b1 &&
+
+	mkdir excluded &&
+	echo problem >excluded/to-be-moved.txt &&
+	git add excluded/to-be-moved.txt &&
+	git commit -m to-be-moved &&
+	git tag split_point &&
+
+	echo b2 >b2 &&
+	git add b2 &&
+	git commit -m b2 &&
+	git tag b2 &&
+
+	git reset --hard split_point &&
+
+	git mv excluded/to-be-moved.txt excluded/moved.txt &&
+	git commit -m move &&
+	git tag b1 &&
+
+	git config core.sparsecheckout true &&
+	echo "/*" >.git/info/sparse-checkout &&
+	echo "!excluded/" >>.git/info/sparse-checkout &&
+	git read-tree -mu HEAD &&
+
+	git merge -m merge b2 &&
+
+	git status >output &&
+	cp output /tmp/a &&
+	test_i18ngrep "nothing to commit" output
+'
+
 test_done
-- 
2.7.4 (Apple Git-66)
Next: Junio C Hamano
Message 1 of 4 in “Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.”
  1. Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.Mikhail Filippov, Sep 11, 2016
  2. Junio C HamanoSep 11, 2016
  3. Mikhail FilippovSep 12, 2016
  4. Mikhail FilippovSep 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.