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

[PATCH v3 3/3] submodule: extend die message on failed checkout with depth argument

From
larsxschneider@gmail.com <larsxschneider@gmail.com>
Date
Dec 20, 2015, 23:19 UTC
Message-ID
<1450653595-22676-4-git-send-email-larsxschneider@gmail.com>
In-Reply-To
<1450653595-22676-1-git-send-email-larsxschneider@gmail.com>
From: Lars Schneider <larsxschneider@gmail.com>

A submodule checkout might fail due missing hashes caused by a shallow fetch operation triggered with the "--depth" argument. Make the user aware of this with an extended die message.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
---
 git-submodule.sh            |  4 ++++
 t/t7406-submodule-update.sh | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 9bc5c5f..b555d87 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -764,6 +764,10 @@ Maybe you want to use 'update --init'?")"
 				command="git checkout $subforce -q"
 				die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
 				say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")"
+				if ! test -z "$depth"
+				then
+					die_msg="$die_msg $(eval_gettext "Commit is probably not on the default branch. Try to remove the '\$depth' argument!")"
+				fi
 				;;
 			rebase)
 				command="git rebase"
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index b5bd976..52b7120 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -31,6 +31,14 @@ test_expect_success 'setup a submodule tree' '
 	git clone super rebasing &&
 	git clone super merging &&
 	git clone super none &&
+	git clone super non-default-branch &&
+	(cd non-default-branch &&
+	 git checkout -b non-default &&
+	 echo "non-default" >file &&
+	 git add file &&
+	 git commit -m "Commit on non-default branch" &&
+	 git checkout master
+	) &&
 	(cd super &&
 	 git submodule add ../submodule submodule &&
 	 test_tick &&
@@ -63,6 +71,15 @@ test_expect_success 'setup a submodule tree' '
 	 git submodule add ../none none &&
 	 test_tick &&
 	 git commit -m "none"
+	) &&
+	(cd super &&
+	 git submodule add ../non-default-branch non-default-branch &&
+	 (cd non-default-branch &&
+	  git checkout non-default
+	 ) &&
+     git add non-default-branch &&
+	 test_tick &&
+	 git commit -m "non-default-branch"
 	)
 '
 
@@ -752,17 +769,29 @@ test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd'
 	)
 '
 
-test_expect_success 'submodule update clone shallow submodule' '
+test_expect_success 'submodule update clone shallow submodule on default branch' '
 	git clone cloned super3 &&
 	pwd=$(pwd) &&
 	(cd super3 &&
 	 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 	 mv -f .gitmodules.tmp .gitmodules &&
+	 git config submodule.non-default-branch.update none &&
 	 git submodule update --init --depth=3 &&
 	 (cd submodule &&
 	  test 1 = $(git log --oneline | wc -l)
 	 )
-)
+	)
+'
+
+test_expect_success 'submodule update clone shallow submodule on non-default branch' '
+	git clone cloned super4 &&
+	pwd=$(pwd) &&
+	(cd super4 &&
+	 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
+	 mv -f .gitmodules.tmp .gitmodules &&
+	 test_must_fail git submodule update --init --depth=3 2>submodule.out &&
+	 test_i18ngrep --count "Commit is probably not on the default branch." submodule.out
+    )
 '
 
 test_expect_success 'submodule update --recursive drops module name before recursing' '
-- 
2.5.1
Previous: larsxschneider@gmail.comNext: Stefan Beller
Message 9 of 14 in “add test to demonstrate that shallow recursive clones fail”
  1. 0/3 add test to demonstrate that shallow recursive clones faillarsxschneider@gmail.com, Dec 20, 2015
  2. 1/3 submodule: add test to demonstrate that shallow recursive clones faillarsxschneider@gmail.com, Dec 20, 2015
  3. Stefan BellerMar 15, 2016
  4. Junio C HamanoMar 15, 2016
  5. Lars SchneiderMar 20, 2016
  6. Jeff KingMar 20, 2016
  7. Stefan BellerMar 20, 2016
  8. 2/3 submodule: fix &&-chain breakagelarsxschneider@gmail.com, Dec 20, 2015
  9. 3/3 submodule: extend die message on failed checkout with depth argumentlarsxschneider@gmail.com, Dec 20, 2015
  10. Stefan BellerJan 11, 2016
  11. Lars SchneiderJan 12, 2016
  12. Stefan BellerJan 12, 2016
  13. Lars SchneiderJan 7, 2016
  14. Stefan BellerJan 11, 2016

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.