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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux