github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/t-ls-files.sh (about) 1 #!/usr/bin/env bash 2 3 . "$(dirname "$0")/testlib.sh" 4 5 begin_test "ls-files" 6 ( 7 set -e 8 9 mkdir repo 10 cd repo 11 git init 12 git lfs track "*.dat" | grep "Tracking \"\*.dat\"" 13 echo "some data" > some.dat 14 echo "some text" > some.txt 15 echo "missing" > missing.dat 16 git add missing.dat 17 git commit -m "add missing file" 18 [ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ] 19 20 git rm missing.dat 21 git add some.dat some.txt 22 git commit -m "added some files, removed missing one" 23 24 git lfs ls-files | tee ls.log 25 grep some.dat ls.log 26 [ `wc -l < ls.log` = 1 ] 27 28 diff -u <(git lfs ls-files --debug) <(cat <<-EOF 29 filepath: some.dat 30 size: 10 31 checkout: true 32 download: true 33 oid: sha256 5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f 34 version: https://git-lfs.github.com/spec/v1 35 36 EOF) 37 ) 38 end_test 39 40 begin_test "ls-files: --size" 41 ( 42 set -e 43 44 reponame="ls-files-size" 45 git init "$reponame" 46 cd "$reponame" 47 48 git lfs track "*.dat" 49 git add .gitattributes 50 git commit -m "initial commit" 51 52 contents="contents" 53 size="$(printf "$contents" | wc -c | awk '{ print $1 }')" 54 printf "$contents" > a.dat 55 56 git add a.dat 57 git commit -m "add a.dat" 58 59 git lfs ls-files --size 2>&1 | tee ls.log 60 [ "d1b2a59fbe * a.dat (8 B)" = "$(cat ls.log)" ] 61 ) 62 end_test 63 64 begin_test "ls-files: indexed files without tree" 65 ( 66 set -e 67 68 reponame="ls-files-indexed-files-without-tree" 69 git init "$reponame" 70 cd "$reponame" 71 72 git lfs track '*.dat' 73 git add .gitattributes 74 75 contents="a" 76 oid="$(calc_oid "$contents")" 77 printf "$contents" > a.dat 78 79 [ "" = "$(git lfs ls-files)" ] 80 81 git add a.dat 82 83 [ "${oid:0:10} * a.dat" = "$(git lfs ls-files)" ] 84 ) 85 end_test 86 87 begin_test "ls-files: indexed file with tree" 88 ( 89 set -e 90 91 reponame="ls-files-indexed-files-with-tree" 92 git init "$reponame" 93 cd "$reponame" 94 95 git lfs track '*.dat' 96 git add .gitattributes 97 git commit -m "initial commit" 98 99 tree_contents="a" 100 tree_oid="$(calc_oid "$tree_contents")" 101 102 printf "$tree_contents" > a.dat 103 git add a.dat 104 git commit -m "add a.dat" 105 106 index_contents="b" 107 index_oid="$(calc_oid "$index_contents")" 108 109 printf "$index_contents" > a.dat 110 git add a.dat 111 112 [ "${index_oid:0:10} * a.dat" = "$(git lfs ls-files)" ] 113 ) 114 end_test 115 116 begin_test "ls-files: outside git repository" 117 ( 118 set +e 119 git lfs ls-files 2>&1 > ls-files.log 120 res=$? 121 122 set -e 123 if [ "$res" = "0" ]; then 124 echo "Passes because $GIT_LFS_TEST_DIR is unset." 125 exit 0 126 fi 127 [ "$res" = "128" ] 128 grep "Not in a git repository" ls-files.log 129 ) 130 end_test 131 132 begin_test "ls-files: --include" 133 ( 134 set -e 135 136 git init ls-files-include 137 cd ls-files-include 138 139 git lfs track "*.dat" "*.bin" 140 echo "a" > a.dat 141 echo "b" > b.dat 142 echo "c" > c.bin 143 144 git add *.gitattributes a.dat b.dat c.bin 145 git commit -m "initial commit" 146 147 git lfs ls-files --include="*.dat" 2>&1 | tee ls-files.log 148 149 [ "0" -eq "$(grep -c "\.bin" ls-files.log)" ] 150 [ "2" -eq "$(grep -c "\.dat" ls-files.log)" ] 151 ) 152 end_test 153 154 begin_test "ls-files: --exclude" 155 ( 156 set -e 157 158 git init ls-files-exclude 159 cd ls-files-exclude 160 161 mkdir dir 162 163 git lfs track "*.dat" 164 echo "a" > a.dat 165 echo "b" > b.dat 166 echo "c" > dir/c.dat 167 168 git add *.gitattributes a.dat b.dat dir/c.dat 169 git commit -m "initial commit" 170 171 git lfs ls-files --exclude="dir/" 2>&1 | tee ls-files.log 172 173 [ "0" -eq "$(grep -c "dir" ls-files.log)" ] 174 [ "2" -eq "$(grep -c "\.dat" ls-files.log)" ] 175 ) 176 end_test 177 178 begin_test "ls-files: before first commit" 179 ( 180 set -e 181 182 reponame="ls-files-before-first-commit" 183 git init "$reponame" 184 cd "$reponame" 185 186 if [ 0 -ne $(git lfs ls-files | wc -l) ]; then 187 echo >&2 "fatal: expected \`git lfs ls-files\` to produce no output" 188 exit 1 189 fi 190 ) 191 end_test 192 193 begin_test "ls-files: show duplicate files" 194 ( 195 set -e 196 197 mkdir dupRepoShort 198 cd dupRepoShort 199 git init 200 201 git lfs track "*.tgz" | grep "Tracking \"\*.tgz\"" 202 echo "test content" > one.tgz 203 echo "test content" > two.tgz 204 git add one.tgz 205 git add two.tgz 206 git commit -m "add duplicate files" 207 208 expected="$(echo "a1fff0ffef * one.tgz 209 a1fff0ffef * two.tgz")" 210 211 [ "$expected" = "$(git lfs ls-files)" ] 212 ) 213 end_test 214 215 begin_test "ls-files: show duplicate files with long OID" 216 ( 217 set -e 218 219 mkdir dupRepoLong 220 cd dupRepoLong 221 git init 222 223 git lfs track "*.tgz" | grep "Tracking \"\*.tgz\"" 224 echo "test content" > one.tgz 225 echo "test content" > two.tgz 226 git add one.tgz 227 git add two.tgz 228 git commit -m "add duplicate files with long OID" 229 230 expected="$(echo "a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * one.tgz 231 a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * two.tgz")" 232 233 [ "$expected" = "$(git lfs ls-files --long)" ] 234 ) 235 end_test 236 237 begin_test "ls-files: history with --all" 238 ( 239 set -e 240 241 reponame="ls-files-history-with-all" 242 git init "$reponame" 243 cd "$reponame" 244 245 git lfs track '*.dat' 246 printf "a" > a.dat 247 printf "b" > b.dat 248 249 git add .gitattributes a.dat b.dat 250 git commit -m "initial commit" 251 252 rm b.dat 253 git add b.dat 254 git commit -m "remove b.dat" 255 256 git lfs ls-files 2>&1 | tee ls-files.log 257 [ 1 -eq $(grep -c "a\.dat" ls-files.log) ] 258 [ 0 -eq $(grep -c "b\.dat" ls-files.log) ] 259 260 git lfs ls-files --all 2>&1 | tee ls-files-all.log 261 [ 1 -eq $(grep -c "a\.dat" ls-files-all.log) ] 262 [ 1 -eq $(grep -c "b\.dat" ls-files-all.log) ] 263 ) 264 end_test 265 266 begin_test "ls-files: --all with argument(s)" 267 ( 268 set -e 269 270 reponame="ls-files-all-with-arguments" 271 git init "$reponame" 272 cd "$reponame" 273 274 git lfs ls-files --all master 2>&1 | tee ls-files.log 275 276 if [ "0" -eq "${PIPESTATUS[0]}" ]; then 277 echo >&2 "fatal: \`git lfs ls-files --all master\` to fail" 278 exit 1 279 fi 280 281 [ "fatal: cannot use --all with explicit reference" = "$(cat ls-files.log)" ] 282 ) 283 end_test 284 285 begin_test "ls-files: reference with --deleted" 286 ( 287 set -e 288 289 reponame="ls-files-reference-with-deleted" 290 git init "$reponame" 291 cd "$reponame" 292 293 git lfs track "*.dat" 294 printf "a" > a.dat 295 git add .gitattributes a.dat 296 git commit -m "initial commit" 297 298 rm a.dat 299 git add a.dat 300 git commit -m "a.dat: remove a.dat" 301 302 git lfs ls-files 2>&1 | tee ls-files.log 303 git lfs ls-files --deleted 2>&1 | tee ls-files-deleted.log 304 305 [ 0 -eq $(grep -c "a\.dat" ls-files.log) ] 306 [ 1 -eq $(grep -c "a\.dat" ls-files-deleted.log) ] 307 ) 308 end_test 309 310 begin_test "ls-files: invalid --all ordering" 311 ( 312 set -e 313 314 reponame="ls-files-invalid---all-ordering" 315 git init "$reponame" 316 cd "$reponame" 317 318 git lfs track "*.dat" 319 echo "Hello world" > a.dat 320 321 git add .gitattributes a.dat 322 git commit -m "initial commit" 323 324 git lfs ls-files -- --all 2>&1 | tee ls-files.out 325 if [ ${PIPESTATUS[0]} = "0" ]; then 326 echo >&2 "fatal: expected \`git lfs ls-files -- --all\' to fail" 327 exit 1 328 fi 329 grep "Could not scan for Git LFS tree" ls-files.out 330 ) 331 end_test 332 333 begin_test "ls-files: list/stat files with escaped runes in path before commit" 334 ( 335 set -e 336 337 reponame=runes-in-path 338 content="zero" 339 checksum="d3eb539a55" 340 pathWithGermanRunes="german/äöü" 341 fileWithGermanRunes="schüüch.bin" 342 343 mkdir $reponame 344 git init "$reponame" 345 cd $reponame 346 git lfs track "**/*" 347 348 echo "$content" > regular 349 echo "$content" > "$fileWithGermanRunes" 350 351 mkdir -p "$pathWithGermanRunes" 352 echo "$content" > "$pathWithGermanRunes/regular" 353 echo "$content" > "$pathWithGermanRunes/$fileWithGermanRunes" 354 355 git add * 356 357 # check short form 358 [ 4 -eq "$(git lfs ls-files | grep -c '*')" ] 359 360 # also check long format 361 [ 4 -eq "$(git lfs ls-files -l | grep -c '*')" ] 362 363 ) 364 end_test