github.com/2lambda123/git-lfs@v2.5.2+incompatible/t/t-post-checkout.sh (about) 1 #!/usr/bin/env bash 2 3 . "$(dirname "$0")/testlib.sh" 4 5 begin_test "post-checkout" 6 ( 7 set -e 8 9 reponame="$(basename "$0" ".sh")" 10 setup_remote_repo "$reponame" 11 12 clone_repo "$reponame" "$reponame" 13 14 git lfs track --lockable "*.dat" 15 git lfs track "*.big" # not lockable 16 git add .gitattributes 17 git commit -m "add git attributes" 18 19 echo "[ 20 { 21 \"CommitDate\":\"$(get_date -10d)\", 22 \"Files\":[ 23 {\"Filename\":\"file1.dat\",\"Data\":\"file 1 creation\"}, 24 {\"Filename\":\"file2.dat\",\"Data\":\"file 2 creation\"}] 25 }, 26 { 27 \"CommitDate\":\"$(get_date -7d)\", 28 \"Files\":[ 29 {\"Filename\":\"file1.dat\",\"Data\":\"file 1 updated commit 2\"}, 30 {\"Filename\":\"file3.big\",\"Data\":\"file 3 creation\"}, 31 {\"Filename\":\"file4.big\",\"Data\":\"file 4 creation\"}], 32 \"Tags\":[\"atag\"] 33 }, 34 { 35 \"CommitDate\":\"$(get_date -5d)\", 36 \"Files\":[ 37 {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated commit 3\"}] 38 }, 39 { 40 \"CommitDate\":\"$(get_date -3d)\", 41 \"NewBranch\":\"branch2\", 42 \"Files\":[ 43 {\"Filename\":\"file5.dat\",\"Data\":\"file 5 creation in branch2\"}, 44 {\"Filename\":\"file6.big\",\"Data\":\"file 6 creation in branch2\"}] 45 }, 46 { 47 \"CommitDate\":\"$(get_date -1d)\", 48 \"Files\":[ 49 {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated in branch2\"}, 50 {\"Filename\":\"file3.big\",\"Data\":\"file 3 updated in branch2\"}] 51 } 52 ]" | GIT_LFS_SET_LOCKABLE_READONLY=0 lfstest-testutils addcommits 53 54 # skipped setting read-only above to make bulk load simpler (no read-only issues) 55 56 git push -u origin master branch2 57 58 # re-clone the repo so we start fresh 59 cd .. 60 rm -rf "$reponame" 61 clone_repo "$reponame" "$reponame" 62 63 # this will be master 64 65 [ "$(cat file1.dat)" == "file 1 updated commit 2" ] 66 [ "$(cat file2.dat)" == "file 2 updated commit 3" ] 67 [ "$(cat file3.big)" == "file 3 creation" ] 68 [ "$(cat file4.big)" == "file 4 creation" ] 69 [ ! -e file5.dat ] 70 [ ! -e file6.big ] 71 # without the post-checkout hook, any changed files would now be writeable 72 refute_file_writeable file1.dat 73 refute_file_writeable file2.dat 74 assert_file_writeable file3.big 75 assert_file_writeable file4.big 76 77 # checkout branch 78 git checkout branch2 79 [ -e file5.dat ] 80 [ -e file6.big ] 81 refute_file_writeable file1.dat 82 refute_file_writeable file2.dat 83 refute_file_writeable file5.dat 84 assert_file_writeable file3.big 85 assert_file_writeable file4.big 86 assert_file_writeable file6.big 87 88 # Confirm that contents of existing files were updated even though were read-only 89 [ "$(cat file2.dat)" == "file 2 updated in branch2" ] 90 [ "$(cat file3.big)" == "file 3 updated in branch2" ] 91 92 93 # restore files inside a branch (causes full scan since no diff) 94 rm -f *.dat 95 [ ! -e file1.dat ] 96 [ ! -e file2.dat ] 97 [ ! -e file5.dat ] 98 git checkout file1.dat file2.dat file5.dat 99 [ "$(cat file1.dat)" == "file 1 updated commit 2" ] 100 [ "$(cat file2.dat)" == "file 2 updated in branch2" ] 101 [ "$(cat file5.dat)" == "file 5 creation in branch2" ] 102 refute_file_writeable file1.dat 103 refute_file_writeable file2.dat 104 refute_file_writeable file5.dat 105 106 # now lock files, then remove & restore 107 git lfs lock file1.dat 108 git lfs lock file2.dat 109 assert_file_writeable file1.dat 110 assert_file_writeable file2.dat 111 rm -f *.dat 112 git checkout file1.dat file2.dat file5.dat 113 assert_file_writeable file1.dat 114 assert_file_writeable file2.dat 115 refute_file_writeable file5.dat 116 117 ) 118 end_test