| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "dedup" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="dedup" |
| 10 | gitscip-shell system . . git. init $reponame |
| 11 | cd $reponame |
| 12 | |
| 13 | # Confirm Git LFS extensions prevent de-duplication |
| 14 | gitscip-shell system . . git. config lfs.extension.foo.clean "foo-clean %f" |
| 15 | gitscip-shell system . . git. config lfs.extension.foo.smudge "foo-smudge %f" |
| 16 | gitscip-shell system . . git. config lfs.extension.foo.priority 0 |
| 17 | |
| 18 | result=$(gitscip-shell system . . git. lfs dedup 2>&1) && truescip-shell system . . true. |
| 19 | if ( echoscip-shell system . . echo. $result | grepscip-shell system . . grep. "This system does not support de-duplication." ); then |
| 20 | exit |
| 21 | fi |
| 22 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . grep. 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.' |
| 23 | |
| 24 | gitscip-shell system . . git. config --unset lfs.extension.foo.clean |
| 25 | gitscip-shell system . . git. config --unset lfs.extension.foo.smudge |
| 26 | gitscip-shell system . . git. config --unset lfs.extension.foo.priority |
| 27 | |
| 28 | # Create a commit with some files tracked by git-lfs |
| 29 | gitscip-shell system . . git. lfs track *.dat |
| 30 | echoscip-shell system . . echo. "test data" > a.dat |
| 31 | echoscip-shell system . . echo. "test data 2" > b.dat |
| 32 | gitscip-shell system . . git. add .gitattributes *.dat |
| 33 | gitscip-shell system . . git. commit -m "first commit" |
| 34 | |
| 35 | # Delete file b and lock directory |
| 36 | bOid=$(gitscip-shell system . . git. log --patch b.dat | grepscip-shell system . . grep. "^+oid" | cutscip-shell system . . cut. -d ":" -f 2) |
| 37 | bOid12=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 1-2) |
| 38 | bOid34=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 3-4) |
| 39 | rmscip-shell system . . rm. ".git/lfs/objects/$bOid12/$bOid34/$bOid" |
| 40 | |
| 41 | # DO |
| 42 | result=$(gitscip-shell system . . git. lfs dedup 2>&1) && truescip-shell system . . true. |
| 43 | |
| 44 | # VERIFY: Expected |
| 45 | # Success: a.dat |
| 46 | # Success: b.dat |
| 47 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . grep. 'Success: a.dat' |
| 48 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . 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 | gitscip-shell system . . git. init $reponame |
| 59 | cd $reponame |
| 60 | |
| 61 | # Confirm Git LFS extensions prevent de-duplication |
| 62 | gitscip-shell system . . git. config lfs.extension.foo.clean "foo-clean %f" |
| 63 | gitscip-shell system . . git. config lfs.extension.foo.smudge "foo-smudge %f" |
| 64 | gitscip-shell system . . git. config lfs.extension.foo.priority 0 |
| 65 | |
| 66 | result=$(gitscip-shell system . . git. lfs dedup --test 2>&1) && truescip-shell system . . true. |
| 67 | if ( echoscip-shell system . . echo. $result | grepscip-shell system . . grep. "This system does not support de-duplication." ); then |
| 68 | exit |
| 69 | fi |
| 70 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . grep. 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.' |
| 71 | |
| 72 | gitscip-shell system . . git. config --unset lfs.extension.foo.clean |
| 73 | gitscip-shell system . . git. config --unset lfs.extension.foo.smudge |
| 74 | gitscip-shell system . . git. config --unset lfs.extension.foo.priority |
| 75 | |
| 76 | # DO |
| 77 | result=$(gitscip-shell system . . git. lfs dedup --test 2>&1) && truescip-shell system . . true. |
| 78 | |
| 79 | # Verify: This platform and repository support file de-duplication. |
| 80 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . 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 | gitscip-shell system . . git. init $reponame |
| 90 | cd $reponame |
| 91 | |
| 92 | # Make working tree dirty. |
| 93 | echoscip-shell system . . echo. "test data" > a.dat |
| 94 | gitscip-shell system . . git. add a.dat |
| 95 | gitscip-shell system . . git. commit -m "first commit" |
| 96 | echoscip-shell system . . echo. "modify" >> a.dat |
| 97 | |
| 98 | # DO |
| 99 | result=$(gitscip-shell system . . git. lfs dedup 2>&1) && truescip-shell system . . true. |
| 100 | if ( echoscip-shell system . . echo. $result | grepscip-shell system . . 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 | echoscip-shell system . . echo. "$result" | grepscip-shell system . . grep. 'Working tree is dirty. Please commit or reset your change.' |
| 106 | ) |
| 107 | end_test |