| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "dedup" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="dedup" |
| 10 | git init $reponame |
| 11 | cd $reponame |
| 12 | |
| 13 | # Confirm Git LFS extensions prevent de-duplication |
| 14 | git config lfs.extension.foo.clean "foo-clean %f" |
| 15 | git config lfs.extension.foo.smudge "foo-smudge %f" |
| 16 | git config lfs.extension.foo.priority 0 |
| 17 | |
| 18 | result=$(git lfs dedup 2>&1) && true |
| 19 | if ( echo $result | grep "This system does not support de-duplication." ); then |
| 20 | exit |
| 21 | fi |
| 22 | echo "$result" | grep 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.' |
| 23 | |
| 24 | git config --unset lfs.extension.foo.clean |
| 25 | git config --unset lfs.extension.foo.smudge |
| 26 | git config --unset lfs.extension.foo.priority |
| 27 | |
| 28 | # Create a commit with some files tracked by git-lfs |
| 29 | git lfs track *.dat |
| 30 | echo "test data" > a.dat |
| 31 | echo "test data 2" > b.dat |
| 32 | git add .gitattributes *.dat |
| 33 | git commit -m "first commit" |
| 34 | |
| 35 | # Delete file b and lock directory |
| 36 | bOid=$(git log --patch b.dat | grep "^+oid" | cut -d ":" -f 2) |
| 37 | bOid12=$(echo $bOid | cut -b 1-2) |
| 38 | bOid34=$(echo $bOid | cut -b 3-4) |
| 39 | rm ".git/lfs/objects/$bOid12/$bOid34/$bOid" |
| 40 | |
| 41 | # DO |
| 42 | result=$(git lfs dedup 2>&1) && true |
| 43 | |
| 44 | # VERIFY: Expected |
| 45 | # Success: a.dat |
| 46 | # Success: b.dat |
| 47 | echo "$result" | grep 'Success: a.dat' |
| 48 | echo "$result" | grep -E 'Success:\s+b.dat|Skipped:\s+b.dat' |
| 49 | # Sometimes mediafile of b.bat is restored by timing issue? |
| 50 | ) |
| 51 | end_test |
| 52 | |
| 53 | begin_test "dedup test" |
| 54 | ( |
| 55 | set -e |
| 56 | |
| 57 | reponame="dedup_test" |
| 58 | git init $reponame |
| 59 | cd $reponame |
| 60 | |
| 61 | # Confirm Git LFS extensions prevent de-duplication |
| 62 | git config lfs.extension.foo.clean "foo-clean %f" |
| 63 | git config lfs.extension.foo.smudge "foo-smudge %f" |
| 64 | git config lfs.extension.foo.priority 0 |
| 65 | |
| 66 | result=$(git lfs dedup --test 2>&1) && true |
| 67 | if ( echo $result | grep "This system does not support de-duplication." ); then |
| 68 | exit |
| 69 | fi |
| 70 | echo "$result" | grep 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.' |
| 71 | |
| 72 | git config --unset lfs.extension.foo.clean |
| 73 | git config --unset lfs.extension.foo.smudge |
| 74 | git config --unset lfs.extension.foo.priority |
| 75 | |
| 76 | # DO |
| 77 | result=$(git lfs dedup --test 2>&1) && true |
| 78 | |
| 79 | # Verify: This platform and repository support file de-duplication. |
| 80 | echo "$result" | grep 'This platform and repository support file de-duplication.' |
| 81 | ) |
| 82 | end_test |
| 83 | |
| 84 | begin_test "dedup dirty workdir" |
| 85 | ( |
| 86 | set -e |
| 87 | |
| 88 | reponame="dedup_dirty_workdir" |
| 89 | git init $reponame |
| 90 | cd $reponame |
| 91 | |
| 92 | # Make working tree dirty. |
| 93 | echo "test data" > a.dat |
| 94 | git add a.dat |
| 95 | git commit -m "first commit" |
| 96 | echo "modify" >> a.dat |
| 97 | |
| 98 | # DO |
| 99 | result=$(git lfs dedup 2>&1) && true |
| 100 | if ( echo $result | grep "This system does not support de-duplication." ); then |
| 101 | exit |
| 102 | fi |
| 103 | |
| 104 | # Verify: Working tree is dirty. Please commit or reset your change. |
| 105 | echo "$result" | grep 'Working tree is dirty. Please commit or reset your change.' |
| 106 | ) |
| 107 | end_test |