github.com/saracen/git-lfs@v2.5.2+incompatible/t/t-fsck.sh (about) 1 #!/usr/bin/env bash 2 3 . "$(dirname "$0")/testlib.sh" 4 5 begin_test "fsck default" 6 ( 7 set -e 8 9 reponame="fsck-default" 10 git init $reponame 11 cd $reponame 12 13 # Create a commit with some files tracked by git-lfs 14 git lfs track *.dat 15 echo "test data" > a.dat 16 echo "test data 2" > b.dat 17 git add .gitattributes *.dat 18 git commit -m "first commit" 19 20 [ "Git LFS fsck OK" = "$(git lfs fsck)" ] 21 22 aOid=$(git log --patch a.dat | grep "^+oid" | cut -d ":" -f 2) 23 aOid12=$(echo $aOid | cut -b 1-2) 24 aOid34=$(echo $aOid | cut -b 3-4) 25 if [ "$aOid" != "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then 26 echo "oid for a.dat does not match" 27 exit 1 28 fi 29 30 bOid=$(git log --patch b.dat | grep "^+oid" | cut -d ":" -f 2) 31 bOid12=$(echo $bOid | cut -b 1-2) 32 bOid34=$(echo $bOid | cut -b 3-4) 33 if [ "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then 34 echo "oid for b.dat does not match" 35 exit 1 36 fi 37 38 39 echo "CORRUPTION" >> .git/lfs/objects/$aOid12/$aOid34/$aOid 40 41 moved=$(native_path "$TRASHDIR/$reponame/.git/lfs/bad") 42 expected="$(printf 'Object a.dat (%s) is corrupt 43 Moving corrupt objects to %s' "$aOid" "$moved")" 44 [ "$expected" = "$(git lfs fsck)" ] 45 46 [ -e ".git/lfs/bad/$aOid" ] 47 [ ! -e ".git/lfs/objects/$aOid12/$aOid34/$aOid" ] 48 [ "$bOid" = "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ] 49 ) 50 end_test 51 52 begin_test "fsck dry run" 53 ( 54 set -e 55 56 reponame="fsck-dry-run" 57 git init $reponame 58 cd $reponame 59 60 # Create a commit with some files tracked by git-lfs 61 git lfs track *.dat 62 echo "test data" > a.dat 63 echo "test data 2" > b.dat 64 git add .gitattributes *.dat 65 git commit -m "first commit" 66 67 [ "Git LFS fsck OK" = "$(git lfs fsck --dry-run)" ] 68 69 aOid=$(git log --patch a.dat | grep "^+oid" | cut -d ":" -f 2) 70 aOid12=$(echo $aOid | cut -b 1-2) 71 aOid34=$(echo $aOid | cut -b 3-4) 72 if [ "$aOid" != "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then 73 echo "oid for a.dat does not match" 74 exit 1 75 fi 76 77 bOid=$(git log --patch b.dat | grep "^+oid" | cut -d ":" -f 2) 78 bOid12=$(echo $bOid | cut -b 1-2) 79 bOid34=$(echo $bOid | cut -b 3-4) 80 if [ "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then 81 echo "oid for b.dat does not match" 82 exit 1 83 fi 84 85 echo "CORRUPTION" >> .git/lfs/objects/$aOid12/$aOid34/$aOid 86 87 [ "Object a.dat ($aOid) is corrupt" = "$(git lfs fsck --dry-run)" ] 88 89 if [ "$aOid" = "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then 90 echo "oid for a.dat still matches match" 91 exit 1 92 fi 93 94 if [ "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then 95 echo "oid for b.dat does not match" 96 exit 1 97 fi 98 ) 99 end_test 100 101 begin_test "fsck: outside git repository" 102 ( 103 set +e 104 git lfs fsck 2>&1 > fsck.log 105 res=$? 106 107 set -e 108 if [ "$res" = "0" ]; then 109 echo "Passes because $GIT_LFS_TEST_DIR is unset." 110 exit 0 111 fi 112 [ "$res" = "128" ] 113 grep "Not in a git repository" fsck.log 114 ) 115 end_test