Merge branch 'jk/http-auth-redirects'
[gitweb.git] / t / t7001-mv.sh
index 101816e718d6149a0e8ee500026455f04a8384ed..d432f42bcbd509b0dae46848d2745eba26fc6872 100755 (executable)
@@ -259,4 +259,132 @@ test_expect_success SYMLINKS 'check moved symlink' '
 
 rm -f moved symlink
 
+test_expect_success 'setup submodule' '
+       git commit -m initial &&
+       git reset --hard &&
+       git submodule add ./. sub &&
+       echo content >file &&
+       git add file &&
+       git commit -m "added sub and file"
+'
+
+test_expect_success 'git mv cannot move a submodule in a file' '
+       test_must_fail git mv sub file
+'
+
+test_expect_success 'git mv moves a submodule with a .git directory and no .gitmodules' '
+       entry="$(git ls-files --stage sub | cut -f 1)" &&
+       git rm .gitmodules &&
+       (
+               cd sub &&
+               rm -f .git &&
+               cp -a ../.git/modules/sub .git &&
+               GIT_WORK_TREE=. git config --unset core.worktree
+       ) &&
+       mkdir mod &&
+       git mv sub mod/sub &&
+       ! test -e sub &&
+       [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
+       (
+               cd mod/sub &&
+               git status
+       ) &&
+       git update-index --refresh &&
+       git diff-files --quiet
+'
+
+test_expect_success 'git mv moves a submodule with gitfile' '
+       rm -rf mod/sub &&
+       git reset --hard &&
+       git submodule update &&
+       entry="$(git ls-files --stage sub | cut -f 1)" &&
+       (
+               cd mod &&
+               git mv ../sub/ .
+       ) &&
+       ! test -e sub &&
+       [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
+       (
+               cd mod/sub &&
+               git status
+       ) &&
+       echo mod/sub >expected &&
+       git config -f .gitmodules submodule.sub.path >actual &&
+       test_cmp expected actual &&
+       git update-index --refresh &&
+       git diff-files --quiet
+'
+
+test_expect_success 'mv does not complain when no .gitmodules file is found' '
+       rm -rf mod/sub &&
+       git reset --hard &&
+       git submodule update &&
+       git rm .gitmodules &&
+       entry="$(git ls-files --stage sub | cut -f 1)" &&
+       git mv sub mod/sub 2>actual.err &&
+       ! test -s actual.err &&
+       ! test -e sub &&
+       [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
+       (
+               cd mod/sub &&
+               git status
+       ) &&
+       git update-index --refresh &&
+       git diff-files --quiet
+'
+
+test_expect_success 'mv will error out on a modified .gitmodules file unless staged' '
+       rm -rf mod/sub &&
+       git reset --hard &&
+       git submodule update &&
+       git config -f .gitmodules foo.bar true &&
+       entry="$(git ls-files --stage sub | cut -f 1)" &&
+       test_must_fail git mv sub mod/sub 2>actual.err &&
+       test -s actual.err &&
+       test -e sub &&
+       git diff-files --quiet -- sub &&
+       git add .gitmodules &&
+       git mv sub mod/sub 2>actual.err &&
+       ! test -s actual.err &&
+       ! test -e sub &&
+       [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
+       (
+               cd mod/sub &&
+               git status
+       ) &&
+       git update-index --refresh &&
+       git diff-files --quiet
+'
+
+test_expect_success 'mv issues a warning when section is not found in .gitmodules' '
+       rm -rf mod/sub &&
+       git reset --hard &&
+       git submodule update &&
+       git config -f .gitmodules --remove-section submodule.sub &&
+       git add .gitmodules &&
+       entry="$(git ls-files --stage sub | cut -f 1)" &&
+       echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
+       git mv sub mod/sub 2>actual.err &&
+       test_i18ncmp expect.err actual.err &&
+       ! test -e sub &&
+       [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
+       (
+               cd mod/sub &&
+               git status
+       ) &&
+       git update-index --refresh &&
+       git diff-files --quiet
+'
+
+test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
+       rm -rf mod/sub &&
+       git reset --hard &&
+       git submodule update &&
+       git mv -n sub mod/sub 2>actual.err &&
+       test -f sub/.git &&
+       git diff-index --exit-code HEAD &&
+       git update-index --refresh &&
+       git diff-files --quiet -- sub .gitmodules
+'
+
 test_done