From: Lars Schneider <larsxschnei...@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 <larsxschnei...@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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to