| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . 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 "uninstall --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 [scip-shell system . . `[`. "$GIT_LFS_TEST_DIR" == "" ]; then |
| 16 | echoscip-shell system . . echo. "Skipping uninstall --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 | gitscip-shell system . . git. lfs uninstall --worktree >out.log |
| 24 | res=$? |
| 25 | set -e |
| 26 | |
| 27 | [scip-shell system . . `[`. "Not in a Git repository." = "$(catscip-shell system . . cat. out.log)" ] |
| 28 | [scip-shell system . . `[`. "0" != "$res" ] |
| 29 | ) |
| 30 | end_test |
| 31 | |
| 32 | begin_test "uninstall --worktree with single working tree" |
| 33 | ( |
| 34 | set -e |
| 35 | |
| 36 | # old values that should be ignored by `uninstall --worktree` |
| 37 | gitscip-shell system . . git. config --global filter.lfs.smudge "global smudge" |
| 38 | gitscip-shell system . . git. config --global filter.lfs.clean "global clean" |
| 39 | gitscip-shell system . . git. config --global filter.lfs.process "global filter" |
| 40 | |
| 41 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-single-tree" |
| 42 | mkdirscip-shell system . . mkdir. "$reponame" |
| 43 | cd "$reponame" |
| 44 | gitscip-shell system . . git. init |
| 45 | gitscip-shell system . . git. lfs install --worktree |
| 46 | |
| 47 | # local configs are correct |
| 48 | [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ] |
| 49 | [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --local filter.lfs.smudge)" ] |
| 50 | [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --worktree filter.lfs.smudge)" ] |
| 51 | [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ] |
| 52 | [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --local filter.lfs.clean)" ] |
| 53 | [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --worktree filter.lfs.clean)" ] |
| 54 | [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config filter.lfs.process)" ] |
| 55 | [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --local filter.lfs.process)" ] |
| 56 | [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --worktree filter.lfs.process)" ] |
| 57 | |
| 58 | # global configs |
| 59 | [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ] |
| 60 | [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ] |
| 61 | [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ] |
| 62 | |
| 63 | gitscip-shell system . . git. lfs uninstall --worktree 2>&1 | teescip-shell system . . tee. uninstall.log |
| 64 | if [scip-shell system . . `[`. ${PIPESTATUS[0]} -ne 0 ]; then |
| 65 | echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs uninstall --worktree' to succeed" |
| 66 | exit 1 |
| 67 | fi |
| 68 | [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Global Git LFS configuration has been removed." uninstall.log)" ] |
| 69 | |
| 70 | # global configs |
| 71 | [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ] |
| 72 | [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ] |
| 73 | [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ] |
| 74 | [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ] |
| 75 | [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config filter.lfs.process)" ] |
| 76 | [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ] |
| 77 | |
| 78 | # local configs are empty |
| 79 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --local filter.lfs.smudge)" ] |
| 80 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.smudge)" ] |
| 81 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --local filter.lfs.clean)" ] |
| 82 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.clean)" ] |
| 83 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --local filter.lfs.process)" ] |
| 84 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.process)" ] |
| 85 | ) |
| 86 | end_test |
| 87 | |
| 88 | begin_test "uninstall --worktree with multiple working trees" |
| 89 | ( |
| 90 | set -e |
| 91 | |
| 92 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-multi-tree" |
| 93 | mkdirscip-shell system . . mkdir. "$reponame" |
| 94 | cd "$reponame" |
| 95 | gitscip-shell system . . git. init |
| 96 | |
| 97 | # old values that should be ignored by `uninstall --worktree` |
| 98 | gitscip-shell system . . git. config --global filter.lfs.smudge "global smudge" |
| 99 | gitscip-shell system . . git. config --global filter.lfs.clean "global clean" |
| 100 | gitscip-shell system . . git. config --global filter.lfs.process "global filter" |
| 101 | gitscip-shell system . . git. config --local filter.lfs.smudge "local smudge" |
| 102 | gitscip-shell system . . git. config --local filter.lfs.clean "local clean" |
| 103 | gitscip-shell system . . git. config --local filter.lfs.process "local filter" |
| 104 | |
| 105 | touchscip-shell system . . touch. a.txt |
| 106 | gitscip-shell system . . git. add a.txt |
| 107 | gitscip-shell system . . git. commit -m "initial commit" |
| 108 | |
| 109 | gitscip-shell system . . git. config core.repositoryformatversion 1 |
| 110 | gitscip-shell system . . git. config extensions.worktreeConfig true |
| 111 | |
| 112 | treename="../$reponame-wt" |
| 113 | gitscip-shell system . . git. worktree add "$treename" |
| 114 | cd "$treename" |
| 115 | |
| 116 | gitscip-shell system . . git. lfs install --worktree |
| 117 | |
| 118 | # worktree configs are correct |
| 119 | [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ] |
| 120 | [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --worktree filter.lfs.smudge)" ] |
| 121 | [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ] |
| 122 | [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --worktree filter.lfs.clean)" ] |
| 123 | [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config filter.lfs.process)" ] |
| 124 | [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --worktree filter.lfs.process)" ] |
| 125 | |
| 126 | # local configs are correct |
| 127 | [scip-shell system . . `[`. "local smudge" = "$(gitscip-shell system . . git. config --local filter.lfs.smudge)" ] |
| 128 | [scip-shell system . . `[`. "local clean" = "$(gitscip-shell system . . git. config --local filter.lfs.clean)" ] |
| 129 | [scip-shell system . . `[`. "local filter" = "$(gitscip-shell system . . git. config --local filter.lfs.process)" ] |
| 130 | |
| 131 | # global configs |
| 132 | [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ] |
| 133 | [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ] |
| 134 | [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ] |
| 135 | |
| 136 | gitscip-shell system . . git. lfs uninstall --worktree 2>&1 | teescip-shell system . . tee. uninstall.log |
| 137 | if [scip-shell system . . `[`. ${PIPESTATUS[0]} -ne 0 ]; then |
| 138 | echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs uninstall --worktree' to succeed" |
| 139 | exit 1 |
| 140 | fi |
| 141 | [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Global Git LFS configuration has been removed." uninstall.log)" ] |
| 142 | |
| 143 | # global configs |
| 144 | [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ] |
| 145 | [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ] |
| 146 | [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ] |
| 147 | |
| 148 | # local configs |
| 149 | [scip-shell system . . `[`. "local smudge" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ] |
| 150 | [scip-shell system . . `[`. "local smudge" = "$(gitscip-shell system . . git. config --local filter.lfs.smudge)" ] |
| 151 | [scip-shell system . . `[`. "local clean" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ] |
| 152 | [scip-shell system . . `[`. "local clean" = "$(gitscip-shell system . . git. config --local filter.lfs.clean)" ] |
| 153 | [scip-shell system . . `[`. "local filter" = "$(gitscip-shell system . . git. config filter.lfs.process)" ] |
| 154 | [scip-shell system . . `[`. "local filter" = "$(gitscip-shell system . . git. config --local filter.lfs.process)" ] |
| 155 | |
| 156 | # worktree configs are empty |
| 157 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.smudge)" ] |
| 158 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.clean)" ] |
| 159 | [scip-shell system . . `[`. "" = "$(gitscip-shell system . . git. config --worktree filter.lfs.process)" ] |
| 160 | ) |
| 161 | end_test |
| 162 | |
| 163 | begin_test "uninstall --worktree without worktreeConfig extension" |
| 164 | ( |
| 165 | set -e |
| 166 | |
| 167 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-multi-tree-no-config" |
| 168 | mkdirscip-shell system . . mkdir. "$reponame" |
| 169 | cd "$reponame" |
| 170 | gitscip-shell system . . git. init |
| 171 | |
| 172 | touchscip-shell system . . touch. a.txt |
| 173 | gitscip-shell system . . git. add a.txt |
| 174 | gitscip-shell system . . git. commit -m "initial commit" |
| 175 | |
| 176 | treename="../$reponame-wt" |
| 177 | gitscip-shell system . . git. worktree add "$treename" |
| 178 | cd "$treename" |
| 179 | |
| 180 | set +e |
| 181 | gitscip-shell system . . git. lfs uninstall --worktree >out.log |
| 182 | res=$? |
| 183 | set -e |
| 184 | |
| 185 | catscip-shell system . . cat. out.log |
| 186 | grepscip-shell system . . grep. -E "error running.*git.*config" out.log |
| 187 | [scip-shell system . . `[`. "$res" -eq 0 ] |
| 188 | ) |
| 189 | end_test |
| 190 | |
| 191 | begin_test "uninstall --worktree with conflicting scope" |
| 192 | ( |
| 193 | set -e |
| 194 | |
| 195 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-scope-conflict" |
| 196 | mkdirscip-shell system . . mkdir. "$reponame" |
| 197 | cd "$reponame" |
| 198 | gitscip-shell system . . git. init |
| 199 | |
| 200 | set +e |
| 201 | gitscip-shell system . . git. lfs uninstall --local --worktree 2>err.log |
| 202 | res=$? |
| 203 | set -e |
| 204 | |
| 205 | [scip-shell system . . `[`. "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(catscip-shell system . . cat. err.log)" ] |
| 206 | [scip-shell system . . `[`. "0" != "$res" ] |
| 207 | |
| 208 | set +e |
| 209 | gitscip-shell system . . git. lfs uninstall --worktree --system 2>err.log |
| 210 | res=$? |
| 211 | set -e |
| 212 | |
| 213 | [scip-shell system . . `[`. "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(catscip-shell system . . cat. err.log)" ] |
| 214 | [scip-shell system . . `[`. "0" != "$res" ] |
| 215 | |
| 216 | set +e |
| 217 | gitscip-shell system . . git. lfs uninstall --worktree --file test-file 2>err.log |
| 218 | res=$? |
| 219 | set -e |
| 220 | |
| 221 | [scip-shell system . . `[`. "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(catscip-shell system . . cat. err.log)" ] |
| 222 | [scip-shell system . . `[`. "0" != "$res" ] |
| 223 | ) |
| 224 | end_test |