| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | # These tests rely on behavior found in Git versions higher than 2.20.0 to |
| 6 | # perform themselves, specifically: |
| 7 | # - worktreeConfig extension support |
| 8 | ensure_git_version_isnt $VERSION_LOWER "2.20.0" |
| 9 | |
| 10 | begin_test "install --worktree outside repository" |
| 11 | ( |
| 12 | set -e |
| 13 | |
| 14 | # If run inside the git-lfs source dir this will update its .git/config & cause issues |
| 15 | if [ "$GIT_LFS_TEST_DIR" == "" ]; then |
| 16 | echo "Skipping install --worktree because GIT_LFS_TEST_DIR is not set" |
| 17 | exit 0 |
| 18 | fi |
| 19 | |
| 20 | has_test_dir || exit 0 |
| 21 | |
| 22 | set +e |
| 23 | git lfs install --worktree >out.log |
| 24 | res=$? |
| 25 | set -e |
| 26 | |
| 27 | [ "Not in a Git repository." = "$(cat out.log)" ] |
| 28 | [ "0" != "$res" ] |
| 29 | ) |
| 30 | end_test |
| 31 | |
| 32 | begin_test "install --worktree with single working tree" |
| 33 | ( |
| 34 | set -e |
| 35 | |
| 36 | # old values that should be ignored by `install --worktree` |
| 37 | git config --global filter.lfs.smudge "global smudge" |
| 38 | git config --global filter.lfs.clean "global clean" |
| 39 | git config --global filter.lfs.process "global filter" |
| 40 | |
| 41 | reponame="$(basename "$0" ".sh")-single-tree" |
| 42 | mkdir "$reponame" |
| 43 | cd "$reponame" |
| 44 | git init |
| 45 | git lfs install --worktree |
| 46 | |
| 47 | # local configs are correct |
| 48 | [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ] |
| 49 | [ "git-lfs smudge -- %f" = "$(git config --local filter.lfs.smudge)" ] |
| 50 | [ "git-lfs smudge -- %f" = "$(git config --worktree filter.lfs.smudge)" ] |
| 51 | [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ] |
| 52 | [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ] |
| 53 | [ "git-lfs clean -- %f" = "$(git config --worktree filter.lfs.clean)" ] |
| 54 | [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ] |
| 55 | [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ] |
| 56 | [ "git-lfs filter-process" = "$(git config --worktree filter.lfs.process)" ] |
| 57 | |
| 58 | # global configs |
| 59 | [ "global smudge" = "$(git config --global filter.lfs.smudge)" ] |
| 60 | [ "global clean" = "$(git config --global filter.lfs.clean)" ] |
| 61 | [ "global filter" = "$(git config --global filter.lfs.process)" ] |
| 62 | ) |
| 63 | end_test |
| 64 | |
| 65 | begin_test "install --worktree with multiple working trees" |
| 66 | ( |
| 67 | set -e |
| 68 | |
| 69 | reponame="$(basename "$0" ".sh")-multi-tree" |
| 70 | mkdir "$reponame" |
| 71 | cd "$reponame" |
| 72 | git init |
| 73 | |
| 74 | # old values that should be ignored by `install --worktree` |
| 75 | git config --global filter.lfs.smudge "global smudge" |
| 76 | git config --global filter.lfs.clean "global clean" |
| 77 | git config --global filter.lfs.process "global filter" |
| 78 | git config --local filter.lfs.smudge "local smudge" |
| 79 | git config --local filter.lfs.clean "local clean" |
| 80 | git config --local filter.lfs.process "local filter" |
| 81 | |
| 82 | touch a.txt |
| 83 | git add a.txt |
| 84 | git commit -m "initial commit" |
| 85 | |
| 86 | git config core.repositoryformatversion 1 |
| 87 | git config extensions.worktreeConfig true |
| 88 | |
| 89 | treename="../$reponame-wt" |
| 90 | git worktree add "$treename" |
| 91 | cd "$treename" |
| 92 | |
| 93 | git lfs install --worktree |
| 94 | |
| 95 | # worktree configs are correct |
| 96 | [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ] |
| 97 | [ "git-lfs smudge -- %f" = "$(git config --worktree filter.lfs.smudge)" ] |
| 98 | [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ] |
| 99 | [ "git-lfs clean -- %f" = "$(git config --worktree filter.lfs.clean)" ] |
| 100 | [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ] |
| 101 | [ "git-lfs filter-process" = "$(git config --worktree filter.lfs.process)" ] |
| 102 | |
| 103 | # local configs are correct |
| 104 | [ "local smudge" = "$(git config --local filter.lfs.smudge)" ] |
| 105 | [ "local clean" = "$(git config --local filter.lfs.clean)" ] |
| 106 | [ "local filter" = "$(git config --local filter.lfs.process)" ] |
| 107 | |
| 108 | # global configs |
| 109 | [ "global smudge" = "$(git config --global filter.lfs.smudge)" ] |
| 110 | [ "global clean" = "$(git config --global filter.lfs.clean)" ] |
| 111 | [ "global filter" = "$(git config --global filter.lfs.process)" ] |
| 112 | ) |
| 113 | end_test |
| 114 | |
| 115 | begin_test "install --worktree without worktreeConfig extension" |
| 116 | ( |
| 117 | set -e |
| 118 | |
| 119 | reponame="$(basename "$0" ".sh")-multi-tree-no-config" |
| 120 | mkdir "$reponame" |
| 121 | cd "$reponame" |
| 122 | git init |
| 123 | |
| 124 | touch a.txt |
| 125 | git add a.txt |
| 126 | git commit -m "initial commit" |
| 127 | |
| 128 | treename="../$reponame-wt" |
| 129 | git worktree add "$treename" |
| 130 | cd "$treename" |
| 131 | |
| 132 | set +e |
| 133 | git lfs install --worktree >out.log |
| 134 | res=$? |
| 135 | set -e |
| 136 | |
| 137 | cat out.log |
| 138 | grep -E "error running.*git.*config" out.log |
| 139 | [ "$res" -eq 2 ] |
| 140 | ) |
| 141 | end_test |
| 142 | |
| 143 | begin_test "install --worktree with conflicting scope" |
| 144 | ( |
| 145 | set -e |
| 146 | |
| 147 | reponame="$(basename "$0" ".sh")-scope-conflict" |
| 148 | mkdir "$reponame" |
| 149 | cd "$reponame" |
| 150 | git init |
| 151 | |
| 152 | set +e |
| 153 | git lfs install --local --worktree 2>err.log |
| 154 | res=$? |
| 155 | set -e |
| 156 | |
| 157 | [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ] |
| 158 | [ "0" != "$res" ] |
| 159 | |
| 160 | set +e |
| 161 | git lfs install --worktree --system 2>err.log |
| 162 | res=$? |
| 163 | set -e |
| 164 | |
| 165 | [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ] |
| 166 | [ "0" != "$res" ] |
| 167 | |
| 168 | set +e |
| 169 | git lfs install --worktree --file test-file 2>err.log |
| 170 | res=$? |
| 171 | set -e |
| 172 | |
| 173 | [ "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(cat err.log)" ] |
| 174 | [ "0" != "$res" ] |
| 175 | ) |
| 176 | end_test |