| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "untrack" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | # no need to setup a remote repo, since this test doesn't need to push or pull |
| 10 | |
| 11 | reponame="untrack" |
| 12 | git init $reponame |
| 13 | cd $reponame |
| 14 | |
| 15 | # track *.jpg once |
| 16 | git lfs track "*.jpg" | grep "Tracking \"\*.jpg\"" |
| 17 | echo "* annex.backend=SHA512E" >> .gitattributes |
| 18 | |
| 19 | git lfs untrack "*.jpg" |
| 20 | |
| 21 | expected="* annex.backend=SHA512E" |
| 22 | [ "$expected" = "$(cat .gitattributes)" ] |
| 23 | ) |
| 24 | end_test |
| 25 | |
| 26 | begin_test "untrack outside git repo" |
| 27 | ( |
| 28 | set -e |
| 29 | |
| 30 | reponame="outside" |
| 31 | mkdir $reponame |
| 32 | cd $reponame |
| 33 | |
| 34 | git lfs untrack "*.foo" || { |
| 35 | # this fails if it's run outside of a git repo using GIT_LFS_TEST_DIR |
| 36 | |
| 37 | # git itself returns an exit status of 128 |
| 38 | # $ git show |
| 39 | # fatal: Not a git repository (or any of the parent directories): .git |
| 40 | # $ echo "$?" |
| 41 | # 128 |
| 42 | |
| 43 | [ "$?" = "128" ] |
| 44 | exit 0 |
| 45 | } |
| 46 | |
| 47 | if [ -n "$GIT_LFS_TEST_DIR" ]; then |
| 48 | echo "GIT_LFS_TEST_DIR should be set outside of any Git repository" |
| 49 | exit 1 |
| 50 | fi |
| 51 | ) |
| 52 | end_test |
| 53 | |
| 54 | begin_test "untrack removes escape sequences" |
| 55 | ( |
| 56 | set -e |
| 57 | |
| 58 | reponame="untrack-remove-escape-sequence" |
| 59 | git init "$reponame" |
| 60 | cd "$reponame" |
| 61 | |
| 62 | git lfs track " " | grep "Tracking \" \"" |
| 63 | assert_attributes_count "[[:space:]]" "filter=lfs" 1 |
| 64 | |
| 65 | git lfs untrack " " | grep "Untracking \" \"" |
| 66 | assert_attributes_count "[[:space:]]" "filter=lfs" 0 |
| 67 | |
| 68 | git lfs track "#" | grep "Tracking \"#\"" |
| 69 | assert_attributes_count "\\#" "filter=lfs" 1 |
| 70 | |
| 71 | git lfs untrack "#" | grep "Untracking \"#\"" |
| 72 | assert_attributes_count "\\#" "filter=lfs" 0 |
| 73 | ) |
| 74 | end_test |
| 75 | |
| 76 | begin_test "untrack removes prefixed patterns (legacy)" |
| 77 | ( |
| 78 | set -e |
| 79 | |
| 80 | reponame="untrack-removes-prefix-patterns-legacy" |
| 81 | git init "$reponame" |
| 82 | cd "$reponame" |
| 83 | |
| 84 | echo "./a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes |
| 85 | printf "a" > a.dat |
| 86 | git add .gitattributes a.dat |
| 87 | git commit -m "initial commit" |
| 88 | |
| 89 | git lfs untrack "./a.dat" |
| 90 | |
| 91 | if [ ! -z "$(cat .gitattributes)" ]; then |
| 92 | echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes" |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | git checkout -- .gitattributes |
| 97 | |
| 98 | git lfs untrack "a.dat" |
| 99 | |
| 100 | if [ ! -z "$(cat .gitattributes)" ]; then |
| 101 | echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes" |
| 102 | exit 1 |
| 103 | fi |
| 104 | ) |
| 105 | end_test |
| 106 | |
| 107 | begin_test "untrack removes prefixed patterns (modern)" |
| 108 | ( |
| 109 | set -e |
| 110 | |
| 111 | reponame="untrack-removes-prefix-patterns-modern" |
| 112 | git init "$reponame" |
| 113 | cd "$reponame" |
| 114 | |
| 115 | echo "a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes |
| 116 | printf "a" > a.dat |
| 117 | git add .gitattributes a.dat |
| 118 | git commit -m "initial commit" |
| 119 | |
| 120 | git lfs untrack "./a.dat" |
| 121 | |
| 122 | if [ ! -z "$(cat .gitattributes)" ]; then |
| 123 | echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes" |
| 124 | exit 1 |
| 125 | fi |
| 126 | |
| 127 | git checkout -- .gitattributes |
| 128 | |
| 129 | git lfs untrack "a.dat" |
| 130 | |
| 131 | if [ ! -z "$(cat .gitattributes)" ]; then |
| 132 | echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes" |
| 133 | exit 1 |
| 134 | fi |
| 135 | ) |
| 136 | end_test |
| 137 | |
| 138 | begin_test "untrack removes escaped pattern in .gitattributes" |
| 139 | ( |
| 140 | set -e |
| 141 | |
| 142 | reponame="untrack-escaped" |
| 143 | git init "$reponame" |
| 144 | cd "$reponame" |
| 145 | |
| 146 | filename="file with spaces.#" |
| 147 | |
| 148 | # emulate multiple instances of the same file in gitattributes |
| 149 | echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes |
| 150 | echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes |
| 151 | echo 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes |
| 152 | |
| 153 | git lfs untrack "$filename" |
| 154 | |
| 155 | if [ ! -z "$(cat .gitattributes)" ]; then |
| 156 | echo >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes even if the file name was escaped" |
| 157 | exit 1 |
| 158 | fi |
| 159 | ) |
| 160 | end_test |
| 161 | |
| 162 | begin_test "untrack works with GIT_WORK_TREE" |
| 163 | ( |
| 164 | set -e |
| 165 | |
| 166 | reponame="untrack-work-tree" |
| 167 | export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git" |
| 168 | mkdir "$GIT_WORK_TREE" "$GIT_DIR" |
| 169 | git init |
| 170 | git lfs track '*.bin' |
| 171 | |
| 172 | grep -F '*.bin filter=lfs diff=lfs merge=lfs -text' "$reponame/.gitattributes" |
| 173 | |
| 174 | git lfs untrack '*.bin' |
| 175 | |
| 176 | [ ! -s "$reponame/.gitattributes" ] |
| 177 | ) |
| 178 | end_test |