diff --no-index: use parse_options() instead of diff_opt_parse()
[gitweb.git] / t / t7406-submodule-update.sh
index 64f322c4cc87493ebc060ae5837495563fe61958..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
 
@@ -137,6 +137,24 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
         git submodule update --init --recursive ../super >../../actual 2>../../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
 '
 
@@ -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' '
@@ -228,13 +246,13 @@ test_expect_success 'submodule update --remote should fetch upstream changes wit
        (
                cd super &&
                git submodule update --remote --force submodule &&
-               git -C submodule log -1 --oneline >actual
-               git -C ../submodule log -1 --oneline master >expect
+               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
+               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 &&
@@ -389,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
@@ -424,6 +450,16 @@ test_expect_success 'submodule update - command in .git/config catches failure -
        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
 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
 Failed to recurse into submodule path '../super'
@@ -446,7 +482,8 @@ test_expect_success 'recursive submodule update - command in .git/config catches
 
 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 &&
@@ -476,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 &&
@@ -488,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 &&
@@ -542,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
         ) &&
@@ -560,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
        )
@@ -578,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
        )
 '
 
@@ -746,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
        )
 '
 
@@ -764,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
        )
 '
 
@@ -784,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
        )
 '
 
@@ -828,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
        )
 '
 
@@ -848,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
        )
 '
@@ -875,7 +920,7 @@ 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 submodule status submodule |cut -c2-41) &&
+       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 &&
@@ -885,7 +930,8 @@ test_expect_success 'submodule update clone shallow submodule' '
                sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
                mv -f .gitmodules.tmp .gitmodules &&
                git submodule update --init --depth=$commit_count &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '
 
@@ -901,7 +947,8 @@ test_expect_success 'submodule update clone shallow submodule outside of depth'
                test_i18ngrep "Direct fetching of that commit failed." actual &&
                git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
                git submodule update --init --depth=1 >actual &&
-               test 1 = $(git -C submodule log --oneline | wc -l)
+               git -C submodule log --oneline >out &&
+               test_line_count = 1 out
        )
 '