diff --no-index: use parse_options() instead of diff_opt_parse()
[gitweb.git] / t / t7406-submodule-update.sh
index 5f278799d5a0ceed90b9297ace552b653026e596..e87164aa8ffdba169ba6f91af99ae3d28f28459b 100755 (executable)
@@ -65,7 +65,7 @@ test_expect_success 'setup a submodule tree' '
         git commit -m "none"
        ) &&
        git clone . recursivesuper &&
-       ( cd recursivesuper
+       ( cd recursivesuper &&
         git submodule add ../super super
        )
 '
@@ -115,17 +115,17 @@ Submodule path '../super/submodule': checked out '$submodulesha1'
 EOF
 
 cat <<EOF >expect2
+Cloning into '$pwd/recursivesuper/super/merging'...
+Cloning into '$pwd/recursivesuper/super/none'...
+Cloning into '$pwd/recursivesuper/super/rebasing'...
+Cloning into '$pwd/recursivesuper/super/submodule'...
 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
 Submodule 'none' ($pwd/none) registered for path '../super/none'
 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
-Cloning into '$pwd/recursivesuper/super/merging'...
 done.
-Cloning into '$pwd/recursivesuper/super/none'...
 done.
-Cloning into '$pwd/recursivesuper/super/rebasing'...
 done.
-Cloning into '$pwd/recursivesuper/super/submodule'...
 done.
 EOF
 
@@ -136,8 +136,26 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
         cd tmp &&
         git submodule update --init --recursive ../super >../../actual 2>../../actual2
        ) &&
-       test_cmp expect actual &&
-       test_cmp expect2 actual2
+       test_i18ncmp expect actual &&
+       sort actual2 >actual2.sorted &&
+       test_i18ncmp expect2 actual2.sorted
+'
+
+cat <<EOF >expect2
+Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
+EOF
+
+test_expect_success 'submodule update --init from and of subdirectory' '
+       git init withsubs &&
+       (cd withsubs &&
+        mkdir foo &&
+        git submodule add "$(pwd)/../rebasing" foo/sub &&
+        (cd foo &&
+         git submodule deinit -f sub &&
+         git submodule update --init sub 2>../../actual2
+        )
+       ) &&
+       test_i18ncmp expect2 actual2
 '
 
 apos="'";
@@ -157,7 +175,7 @@ test_expect_success 'submodule update does not fetch already present commits' '
          git submodule update > ../actual 2> ../actual.err
        ) &&
        test_i18ncmp expected actual &&
-       ! test -s actual.err
+       test_must_be_empty actual.err
 '
 
 test_expect_success 'submodule update should fail due to local changes' '
@@ -209,9 +227,42 @@ test_expect_success 'submodule update --remote should fetch upstream changes' '
        )
 '
 
+test_expect_success 'submodule update --remote should fetch upstream changes with .' '
+       (
+               cd super &&
+               git config -f .gitmodules submodule."submodule".branch "." &&
+               git add .gitmodules &&
+               git commit -m "submodules: update from the respective superproject branch"
+       ) &&
+       (
+               cd submodule &&
+               echo line4a >> file &&
+               git add file &&
+               test_tick &&
+               git commit -m "upstream line4a" &&
+               git checkout -b test-branch &&
+               test_commit on-test-branch
+       ) &&
+       (
+               cd super &&
+               git submodule update --remote --force submodule &&
+               git -C submodule log -1 --oneline >actual &&
+               git -C ../submodule log -1 --oneline master >expect &&
+               test_cmp expect actual &&
+               git checkout -b test-branch &&
+               git submodule update --remote --force submodule &&
+               git -C submodule log -1 --oneline >actual &&
+               git -C ../submodule log -1 --oneline test-branch >expect &&
+               test_cmp expect actual &&
+               git checkout master &&
+               git branch -d test-branch &&
+               git reset --hard HEAD^
+       )
+'
+
 test_expect_success 'local config should override .gitmodules branch' '
        (cd submodule &&
-        git checkout -b test-branch &&
+        git checkout test-branch &&
         echo line5 >> file &&
         git add file &&
         test_tick &&
@@ -356,6 +407,14 @@ test_expect_success 'submodule update - command in .git/config' '
        )
 '
 
+test_expect_success 'submodule update - command in .gitmodules is ignored' '
+       test_when_finished "git -C super reset --hard HEAD^" &&
+       git -C super config -f .gitmodules submodule.submodule.update "!false" &&
+       git -C super commit -a -m "add command to .gitmodules file" &&
+       git -C super/submodule reset --hard $submodulesha1^ &&
+       git -C super submodule update submodule
+'
+
 cat << EOF >expect
 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
 EOF
@@ -370,7 +429,7 @@ test_expect_success 'submodule update - command in .git/config catches failure'
        (cd super &&
         test_must_fail git submodule update submodule 2>../actual
        ) &&
-       test_cmp actual expect
+       test_i18ncmp actual expect
 '
 
 cat << EOF >expect
@@ -388,7 +447,17 @@ test_expect_success 'submodule update - command in .git/config catches failure -
         mkdir tmp && cd tmp &&
         test_must_fail git submodule update ../submodule 2>../../actual
        ) &&
-       test_cmp actual expect
+       test_i18ncmp actual expect
+'
+
+test_expect_success 'submodule update - command run for initial population of submodule' '
+       cat >expect <<-EOF &&
+       Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
+       EOF
+       rm -rf super/submodule &&
+       test_must_fail git -C super submodule update 2>actual &&
+       test_i18ncmp expect actual &&
+       git -C super submodule update --checkout
 '
 
 cat << EOF >expect
@@ -408,12 +477,13 @@ test_expect_success 'recursive submodule update - command in .git/config catches
         mkdir -p tmp && cd tmp &&
         test_must_fail git submodule update --recursive ../super 2>../../actual
        ) &&
-       test_cmp actual expect
+       test_i18ncmp actual expect
 '
 
 test_expect_success 'submodule init does not copy command into .git/config' '
        (cd super &&
-        H=$(git ls-files -s submodule | cut -d" " -f2) &&
+        git ls-files -s submodule >out &&
+        H=$(cut -d" " -f2 out) &&
         mkdir submodule1 &&
         git update-index --add --cacheinfo 160000 $H submodule1 &&
         git config -f .gitmodules submodule.submodule1.path submodule1 &&
@@ -443,6 +513,7 @@ test_expect_success 'submodule init picks up merge' '
 '
 
 test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
+       test_config -C super submodule.submodule.update checkout &&
        (cd super &&
         rm -rf submodule &&
         git submodule update submodule &&
@@ -455,6 +526,7 @@ test_expect_success 'submodule update --merge  - ignores --merge  for new submod
 '
 
 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
+       test_config -C super submodule.submodule.update checkout &&
        (cd super &&
         rm -rf submodule &&
         git submodule update submodule &&
@@ -509,9 +581,11 @@ test_expect_success 'submodule update - update=none in .git/config' '
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         (cd submodule &&
          compare_head
         ) &&
@@ -527,11 +601,13 @@ test_expect_success 'submodule update - update=none in .git/config but --checkou
          git checkout master &&
          compare_head
         ) &&
-        git diff --raw | grep "        submodule" &&
+        git diff --name-only >out &&
+        grep ^submodule$ out &&
         git submodule update --checkout &&
-        test_must_fail git diff --raw \| grep "        submodule" &&
+        git diff --name-only >out &&
+        ! grep ^submodule$ out &&
         (cd submodule &&
-         test_must_fail compare_head
+         ! compare_head
         ) &&
         git config --unset submodule.submodule.update
        )
@@ -545,8 +621,8 @@ test_expect_success 'submodule update --init skips submodule with update=none' '
        git clone super cloned &&
        (cd cloned &&
         git submodule update --init &&
-        test -e submodule/.git &&
-        test_must_fail test -e none/.git
+        test_path_exists submodule/.git &&
+        test_path_is_missing none/.git
        )
 '
 
@@ -713,7 +789,7 @@ test_expect_success 'submodule add places git-dir in superprojects git-dir' '
         (cd .git/modules/deeper/submodule &&
          git log > ../../../../actual
         ) &&
-        test_cmp actual expected
+        test_cmp expected actual
        )
 '
 
@@ -731,7 +807,7 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir' '
         (cd .git/modules/deeper/submodule &&
          git log > ../../../../actual
         ) &&
-        test_cmp actual expected
+        test_cmp expected actual
        )
 '
 
@@ -751,7 +827,7 @@ test_expect_success 'submodule add places git-dir in superprojects git-dir recur
         git add deeper/submodule &&
         git commit -m "update submodule" &&
         git push origin : &&
-        test_cmp actual expected
+        test_cmp expected actual
        )
 '
 
@@ -795,10 +871,10 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re
         (cd submodule/subsubmodule &&
          git log > ../../expected
         ) &&
-        (cd .git/modules/submodule/modules/subsubmodule
+        (cd .git/modules/submodule/modules/subsubmodule &&
          git log > ../../../../../actual
-        )
-        test_cmp actual expected
+        ) &&
+        test_cmp expected actual
        )
 '
 
@@ -815,16 +891,18 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         H=$(git rev-parse --short HEAD) &&
         git commit -am "pre move" &&
         H2=$(git rev-parse --short HEAD) &&
-        git status | sed "s/$H/XXX/" >expect &&
-        H=$(cd submodule2; git rev-parse HEAD) &&
+        git status >out &&
+        sed "s/$H/XXX/" out >expect &&
+        H=$(cd submodule2 && git rev-parse HEAD) &&
         git rm --cached submodule2 &&
         rm -rf submodule2 &&
         mkdir -p "moved/sub module" &&
         git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
-        git config -f .gitmodules submodule.submodule2.path "moved/sub module"
+        git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
         git commit -am "post move" &&
         git submodule update &&
-        git status | sed "s/$H2/XXX/" >actual &&
+        git status > out &&
+        sed "s/$H2/XXX/" out >actual &&
         test_cmp expect actual
        )
 '
@@ -841,16 +919,37 @@ test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd'
 '
 
 test_expect_success 'submodule update clone shallow submodule' '
+       test_when_finished "rm -rf super3" &&
+       first=$(git -C cloned rev-parse HEAD:submodule) &&
+       second=$(git -C submodule rev-parse HEAD) &&
+       commit_count=$(git -C submodule rev-list --count $first^..$second) &&
        git clone cloned super3 &&
        pwd=$(pwd) &&
-       (cd super3 &&
-        sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
-        mv -f .gitmodules.tmp .gitmodules &&
-        git submodule update --init --depth=3
-        (cd submodule &&
-         test 1 = $(git log --oneline | wc -l)
-        )
-)
+       (
+               cd super3 &&
+               sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
+               mv -f .gitmodules.tmp .gitmodules &&
+               git submodule update --init --depth=$commit_count &&
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
+       )
+'
+
+test_expect_success 'submodule update clone shallow submodule outside of depth' '
+       test_when_finished "rm -rf super3" &&
+       git clone cloned super3 &&
+       pwd=$(pwd) &&
+       (
+               cd super3 &&
+               sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
+               mv -f .gitmodules.tmp .gitmodules &&
+               test_must_fail git submodule update --init --depth=1 2>actual &&
+               test_i18ngrep "Direct fetching of that commit failed." actual &&
+               git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
+               git submodule update --init --depth=1 >actual &&
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
+       )
 '
 
 test_expect_success 'submodule update --recursive drops module name before recursing' '