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

[PATCH 4/4] submodule: submodule_move_head omits old argument in forced case

From
Stefan Beller <sbeller@google.com>
Date
Dec 20, 2017, 22:17 UTC
Message-ID
<20171220221725.129162-5-sbeller@google.com>
In-Reply-To
<20171220221725.129162-1-sbeller@google.com>

When using hard reset or forced checkout with the option to recurse into submodules, the submodules need to be reset, too.

It turns out that we need to omit the duplicate old argument to read-tree in all forced cases to omit the 2 way merge and use the more assertive behavior of reading the specific new tree into the index and updating the working tree.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c               |  4 +++-
 t/lib-submodule-update.sh | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/submodule.c b/submodule.c
index fa25888783..db0f7ac51e 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1653,7 +1653,9 @@ int submodule_move_head(const char *path,
 	else
 		argv_array_push(&cp.args, "-m");
 
-	argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+	if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
+		argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+
 	argv_array_push(&cp.args, new ? new : EMPTY_TREE_SHA1_HEX);
 
 	if (run_command(&cp)) {
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index fb0173ea87..380ef4b4ae 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -1015,4 +1015,15 @@ test_submodule_forced_switch_recursing_with_args () {
 			test_submodule_content sub1 origin/modify_sub1
 		)
 	'
+
+	test_expect_success "$command: changed submodule worktree is reset" '
+		prolog &&
+		reset_work_tree_to_interested add_sub1 &&
+		(
+			cd submodule_update &&
+			rm sub1/file1 &&
+			$command HEAD &&
+			test_path_is_file sub1/file1
+		)
+	'
 }
-- 
2.15.1.620.gb9897f4670-goog
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 7 in “[PATCHv2 0/4] Fix --recurse-submodules for submodule worktree changes”
  1. Stefan BellerDec 20, 2017
  2. 1/4 t/lib-submodule-update.sh: clarify testStefan Beller, Dec 20, 2017
  3. 2/4 t/lib-submodule-update.sh: Fix test ignoring ignored files in submodulesStefan Beller, Dec 20, 2017
  4. 3/4 unpack-trees: Fix same() for submodulesStefan Beller, Dec 20, 2017
  5. Junio C HamanoDec 22, 2017
  6. 4/4 submodule: submodule_move_head omits old argument in forced caseStefan Beller, Dec 20, 2017
  7. Junio C HamanoDec 22, 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.