git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Yaroslav Halchenko <debian@onerussian.com>
To: git@vger.kernel.org
Cc: Yaroslav Halchenko <debian@onerussian.com>
Subject: [PATCH 2/2] RF+ENH(TST): compare the entire list of submodule status --recursive to stay intact
Date: Mon, 10 Dec 2018 23:08:39 -0500
Message-ID: <20181211040839.17472-2-debian@onerussian.com> (raw)
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


  reply index

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 17:35 [wishlist] git submodule update --reset-hard Yaroslav Halchenko
2018-12-06 18:29 ` Stefan Beller
2018-12-06 21:24   ` Yaroslav Halchenko
2018-12-06 21:55     ` Stefan Beller
2018-12-07  1:22       ` Yaroslav Halchenko
2018-12-07 21:55         ` Stefan Beller
2018-12-08  2:15           ` Yaroslav Halchenko
2018-12-08  4:21             ` Yaroslav Halchenko
2018-12-10 18:58               ` Stefan Beller
2018-12-10 20:14                 ` Yaroslav Halchenko
2018-12-11  4:08                 ` [PATCH 1/2] submodule: Add --reset-hard option for git submodule update Yaroslav Halchenko
2018-12-11  4:08                   ` Yaroslav Halchenko [this message]
2018-12-12 19:48                     ` [PATCH 2/2] RF+ENH(TST): compare the entire list of submodule status --recursive to stay intact Stefan Beller
2018-12-13 16:42                       ` Yaroslav O Halchenko
2018-12-13 20:44                         ` Stefan Beller
2018-12-13 22:43                           ` Yaroslav O Halchenko
2018-12-13 23:58                             ` Stefan Beller
2018-12-14  4:22                               ` Yaroslav O Halchenko

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181211040839.17472-2-debian@onerussian.com \
    --to=debian@onerussian.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox