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

[PATCH 1/3] merge-recursive.c: conflict using sparse should update file

From
KWKevin Willford <kcwillford@gmail.com>
Date
Apr 7, 2017, 19:23 UTC
Message-ID
<20170407192357.948-2-kewillf@microsoft.com>
In-Reply-To
<20170407192357.948-1-kewillf@microsoft.com>

Update the file when there is a conflict with a modify/delete scenario when using the sparse-checkout feature since the file might not be on disk because the skip-worktree bit is on and the user will need the file and content to determine how to resolve the conflict.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
---
 merge-recursive.c                |  8 ++++++++
 t/t7614-merge-sparse-checkout.sh | 27 +++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100755 t/t7614-merge-sparse-checkout.sh
diff --git a/merge-recursive.c b/merge-recursive.c
index b7ff1ada3c..54fce93dae 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1103,6 +1103,14 @@ static int handle_change_delete(struct merge_options *o,
 			       "and %s in %s. Version %s of %s left in tree."),
 			       change, path, o->branch2, change_past,
 			       o->branch1, o->branch1, path);
+			/*
+			 * In a sparse checkout the file may not exist. Sadly,
+			 * the CE_SKIP_WORKTREE flag is not preserved in the
+			 * case of conflicts, therefore we do the next best
+			 * thing: verify that the file exists.
+			 */
+			if (!file_exists(path))
+				ret = update_file(o, 0, a_oid, a_mode, path);
 		} else {
 			output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
 			       "and %s in %s. Version %s of %s left in tree at %s."),
diff --git a/t/t7614-merge-sparse-checkout.sh b/t/t7614-merge-sparse-checkout.sh
new file mode 100755
index 0000000000..6922f0244f
--- /dev/null
+++ b/t/t7614-merge-sparse-checkout.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='merge can handle sparse-checkout'
+
+. ./test-lib.sh
+
+# merges with conflicts
+
+test_expect_success 'setup' '
+	test_commit a &&
+	test_commit file &&
+	git checkout -b delete-file &&
+	git rm file.t &&
+	test_tick &&
+	git commit -m "remove file" &&
+	git checkout master &&
+	test_commit modify file.t changed
+'
+
+test_expect_success 'merge conflict deleted file and modified' '
+	echo "/a" >.git/info/sparse-checkout &&
+	test_config core.sparsecheckout true &&
+	test_must_fail git merge delete-file &&
+	test_path_is_file file.t
+'
+
+test_done
-- 
2.12.2.windows.2.1.g7df5db8d31
Previous: Kevin WillfordNext: Duy Nguyen
Message 2 of 16 in “fix working directory file issues while using sparse-checkout”
  1. 0/3 fix working directory file issues while using sparse-checkoutKevin Willford, Apr 7, 2017
  2. 1/3 merge-recursive.c: conflict using sparse should update fileKevin Willford, Apr 7, 2017
  3. Duy NguyenApr 10, 2017
  4. 2/3 apply.c: do not checkout file when skip-worktree bit setKevin Willford, Apr 7, 2017
  5. Stefan BellerApr 7, 2017
  6. Duy NguyenApr 10, 2017
  7. 3/3 reset.c: update files when using sparse to avoid data loss.Kevin Willford, Apr 7, 2017
  8. Stefan BellerApr 7, 2017
  9. Duy NguyenApr 10, 2017
  10. Kevin WillfordApr 11, 2017
  11. Duy NguyenApr 12, 2017
  12. Kevin WillfordApr 12, 2017
  13. Duy NguyenApr 16, 2017
  14. Duy NguyenApr 17, 2017
  15. Stefan BellerApr 7, 2017
  16. Stefan BellerApr 7, 2017

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.