Merge branch 'maint-1.8.5' into maint-1.9
[gitweb.git] / t / t7001-mv.sh
index 3bfdfed1f7774edb8a87864bdb6a021dc6a185ed..c8ff9115ec51ded977bcdcef0346b9a7dbaca2e6 100755 (executable)
@@ -294,7 +294,8 @@ test_expect_success 'setup submodule' '
        git submodule add ./. sub &&
        echo content >file &&
        git add file &&
-       git commit -m "added sub and file"
+       git commit -m "added sub and file" &&
+       git branch submodule
 '
 
 test_expect_success 'git mv cannot move a submodule in a file' '
@@ -307,7 +308,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm
        (
                cd sub &&
                rm -f .git &&
-               cp -a ../.git/modules/sub .git &&
+               cp -R -P -p ../.git/modules/sub .git &&
                GIT_WORK_TREE=. git config --unset core.worktree
        ) &&
        mkdir mod &&
@@ -330,7 +331,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
        (
                cd sub &&
                rm -f .git &&
-               cp -a ../.git/modules/sub .git &&
+               cp -R -P -p ../.git/modules/sub .git &&
                GIT_WORK_TREE=. git config --unset core.worktree
        ) &&
        mkdir mod &&
@@ -442,4 +443,35 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
        git diff-files --quiet -- sub .gitmodules
 '
 
+test_expect_success 'checking out a commit before submodule moved needs manual updates' '
+       git mv sub sub2 &&
+       git commit -m "moved sub to sub2" &&
+       git checkout -q HEAD^ 2>actual &&
+       echo "warning: unable to rmdir sub2: Directory not empty" >expected &&
+       test_i18ncmp expected actual &&
+       git status -s sub2 >actual &&
+       echo "?? sub2/" >expected &&
+       test_cmp expected actual &&
+       ! test -f sub/.git &&
+       test -f sub2/.git &&
+       git submodule update &&
+       test -f sub/.git &&
+       rm -rf sub2 &&
+       git diff-index --exit-code HEAD &&
+       git update-index --refresh &&
+       git diff-files --quiet -- sub .gitmodules &&
+       git status -s sub2 >actual &&
+       ! test -s actual
+'
+
+test_expect_success 'mv -k does not accidentally destroy submodules' '
+       git checkout submodule &&
+       mkdir dummy dest &&
+       git mv -k dummy sub dest &&
+       git status --porcelain >actual &&
+       grep "^R  sub -> dest/sub" actual &&
+       git reset --hard &&
+       git checkout .
+'
+
 test_done