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

[PATCH 2/2] RF+ENH(TST): compare the entire list of submodule status --recursive to stay intact

From
Yaroslav Halchenko <debian@onerussian.com>
Date
Dec 11, 2018, 04:08 UTC
Message-ID
<20181211040839.17472-2-debian@onerussian.com>
In-Reply-To
<20181211040839.17472-1-debian@onerussian.com>

For submodule update --reset-hard the best test is comparison of the entire status as shown by submodule status --recursive. Upon update --reset-hard we should get back to the original state, with all the branches being the same (no detached HEAD) and commits identical to original (so no merges, new commits, etc).

For that, I have introduced two helpers: {record,compare}_submodules_status and an additional test for --reset-hard in nested submodule.

I have kept this as a separate PATCH to demonstrate the diff from the original test composition as introduced in the prior patch, and this one where all tests could be of the same type:

    record_submodule_status &&
    perform evil actions &&
    ! compare_submodule_status &&   # to double check that evil was done
    git submodule --reset-hard . &&
    compare_submodule_status        # assure that we are all good
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
---
 t/t7406-submodule-update.sh | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 2e08e0047c..1927424f47 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -21,6 +21,17 @@ compare_head()
     test "$sha_master" = "$sha_head"
 }
 
+record_submodules_status()
+{
+	git submodule status --recursive >expect
+}
+
+compare_submodules_status()
+{
+	git submodule status --recursive >actual &&
+	test_i18ncmp expect actual
+}
+
 
 test_expect_success 'setup a submodule tree' '
 	echo file > file &&
@@ -294,7 +305,7 @@ test_expect_success 'submodule update --rebase staying on master' '
 
 test_expect_success 'submodule update --merge staying on master' '
 	(cd super/submodule &&
-	  git reset --hard HEAD~1
+	 git reset --hard HEAD~1
 	) &&
 	(cd super &&
 	 (cd submodule &&
@@ -307,16 +318,28 @@ test_expect_success 'submodule update --merge staying on master' '
 '
 
 test_expect_success 'submodule update --reset-hard staying on master' '
-	(cd super/submodule &&
-	  git reset --hard HEAD~1
-	) &&
 	(cd super &&
+	 record_submodules_status &&
 	 (cd submodule &&
-	  compare_head
+	  git reset --hard HEAD~1
 	 ) &&
+	 ! compare_submodules_status &&
 	 git submodule update --reset-hard submodule &&
-	 cd submodule &&
-	 compare_head
+	 compare_submodules_status
+	)
+'
+
+test_expect_success 'submodule update --reset-hard in nested submodule' '
+	(cd recursivesuper &&
+	 git submodule update --init --recursive &&
+	 record_submodules_status &&
+	 (cd super/submodule &&
+	  echo 123 >> file &&
+	  git commit -m "new commit" file
+	 ) &&
+	 ! compare_submodules_status &&
+	 git submodule update --reset-hard --recursive &&
+	 compare_submodules_status
 	)
 '
 
-- 
2.20.0.rc2.8.g0a3bec4a1c.dirty
Previous: Yaroslav HalchenkoNext: Stefan Beller
Message 12 of 18 in “[wishlist] git submodule update --reset-hard”
  1. Yaroslav HalchenkoDec 6, 2018
  2. Stefan BellerDec 6, 2018
  3. Yaroslav HalchenkoDec 6, 2018
  4. Stefan BellerDec 6, 2018
  5. Yaroslav HalchenkoDec 7, 2018
  6. Stefan BellerDec 7, 2018
  7. Yaroslav HalchenkoDec 8, 2018
  8. Yaroslav HalchenkoDec 8, 2018
  9. Stefan BellerDec 10, 2018
  10. Yaroslav HalchenkoDec 10, 2018
  11. 1/2 submodule: Add --reset-hard option for git submodule updateYaroslav Halchenko, Dec 11, 2018
  12. 2/2 RF+ENH(TST): compare the entire list of submodule status --recursive to stay intactYaroslav Halchenko, Dec 11, 2018
  13. Stefan BellerDec 12, 2018
  14. Yaroslav O HalchenkoDec 13, 2018
  15. Stefan BellerDec 13, 2018
  16. Yaroslav O HalchenkoDec 13, 2018
  17. Stefan BellerDec 13, 2018
  18. Yaroslav O HalchenkoDec 14, 2018

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.