github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/t-pull.sh (about) 1 #!/usr/bin/env bash 2 3 . "$(dirname "$0")/testlib.sh" 4 5 begin_test "pull" 6 ( 7 set -e 8 9 reponame="$(basename "$0" ".sh")" 10 setup_remote_repo "$reponame" 11 12 clone_repo "$reponame" clone 13 clone_repo "$reponame" repo 14 15 git lfs track "*.dat" 2>&1 | tee track.log 16 grep "Tracking \"\*.dat\"" track.log 17 18 contents="a" 19 contents_oid=$(calc_oid "$contents") 20 contents2="A" 21 contents2_oid=$(calc_oid "$contents2") 22 contents3="dir" 23 contents3_oid=$(calc_oid "$contents3") 24 25 mkdir dir 26 echo "*.log" > .gitignore 27 printf "$contents" > a.dat 28 printf "$contents2" > á.dat 29 printf "$contents3" > dir/dir.dat 30 git add . 31 git commit -m "add files" 2>&1 | tee commit.log 32 grep "master (root-commit)" commit.log 33 grep "5 files changed" commit.log 34 grep "create mode 100644 a.dat" commit.log 35 grep "create mode 100644 .gitattributes" commit.log 36 37 ls -al 38 [ "a" = "$(cat a.dat)" ] 39 [ "A" = "$(cat "á.dat")" ] 40 [ "dir" = "$(cat "dir/dir.dat")" ] 41 42 assert_pointer "master" "a.dat" "$contents_oid" 1 43 assert_pointer "master" "á.dat" "$contents2_oid" 1 44 assert_pointer "master" "dir/dir.dat" "$contents3_oid" 3 45 46 refute_server_object "$reponame" "$contents_oid" 47 refute_server_object "$reponame" "$contents2_oid" 48 refute_server_object "$reponame" "$contents33oid" 49 50 echo "initial push" 51 git push origin master 2>&1 | tee push.log 52 grep "Uploading LFS objects: 100% (3/3), 5 B" push.log 53 grep "master -> master" push.log 54 55 assert_server_object "$reponame" "$contents_oid" 56 assert_server_object "$reponame" "$contents2_oid" 57 assert_server_object "$reponame" "$contents3_oid" 58 59 # change to the clone's working directory 60 cd ../clone 61 62 echo "normal pull" 63 git pull 2>&1 64 65 [ "a" = "$(cat a.dat)" ] 66 [ "A" = "$(cat "á.dat")" ] 67 68 assert_local_object "$contents_oid" 1 69 assert_local_object "$contents2_oid" 1 70 assert_clean_status 71 72 echo "lfs pull" 73 rm -r a.dat á.dat dir # removing files makes the status dirty 74 rm -rf .git/lfs/objects 75 git lfs pull 2>&1 | grep "Downloading LFS objects: 100% (3/3), 5 B" 76 ls -al 77 [ "a" = "$(cat a.dat)" ] 78 [ "A" = "$(cat "á.dat")" ] 79 assert_local_object "$contents_oid" 1 80 assert_local_object "$contents2_oid" 1 81 82 echo "lfs pull with remote" 83 rm -r a.dat á.dat dir 84 rm -rf .git/lfs/objects 85 git lfs pull origin 2>&1 | grep "Downloading LFS objects: 100% (3/3), 5 B" 86 [ "a" = "$(cat a.dat)" ] 87 [ "A" = "$(cat "á.dat")" ] 88 assert_local_object "$contents_oid" 1 89 assert_local_object "$contents2_oid" 1 90 assert_clean_status 91 92 echo "lfs pull with local storage" 93 rm a.dat á.dat 94 git lfs pull 95 [ "a" = "$(cat a.dat)" ] 96 [ "A" = "$(cat "á.dat")" ] 97 assert_clean_status 98 99 echo "lfs pull with include/exclude filters in gitconfig" 100 rm -rf .git/lfs/objects 101 git config "lfs.fetchinclude" "a*" 102 git lfs pull 103 assert_local_object "$contents_oid" 1 104 assert_clean_status 105 106 rm -rf .git/lfs/objects 107 git config --unset "lfs.fetchinclude" 108 git config "lfs.fetchexclude" "a*" 109 git lfs pull 110 refute_local_object "$contents_oid" 111 assert_clean_status 112 113 echo "lfs pull with include/exclude filters in command line" 114 git config --unset "lfs.fetchexclude" 115 rm -rf .git/lfs/objects 116 git lfs pull --include="a*" 117 assert_local_object "$contents_oid" 1 118 assert_clean_status 119 120 rm -rf .git/lfs/objects 121 git lfs pull --exclude="a*" 122 refute_local_object "$contents_oid" 123 assert_clean_status 124 125 echo "resetting to test status" 126 git reset --hard 127 assert_clean_status 128 129 echo "lfs pull clean status" 130 git lfs pull 131 assert_clean_status 132 133 echo "lfs pull with -I" 134 git lfs pull -I "*.dat" 135 assert_clean_status 136 137 echo "lfs pull in subdir" 138 cd dir 139 git lfs pull 140 assert_clean_status 141 142 echo "lfs pull in subdir with -I" 143 git lfs pull -I "*.dat" 144 assert_clean_status 145 ) 146 end_test 147 148 begin_test "pull without clean filter" 149 ( 150 set -e 151 152 GIT_LFS_SKIP_SMUDGE=1 git clone $GITSERVER/t-pull no-clean 153 cd no-clean 154 git lfs uninstall 155 git config --list > config.txt 156 grep "filter.lfs.clean" config.txt && { 157 echo "clean filter still configured:" 158 cat config.txt 159 exit 1 160 } 161 162 contents="a" 163 contents_oid=$(calc_oid "$contents") 164 165 # LFS object not downloaded, pointer in working directory 166 grep "$contents_oid" a.dat || { 167 echo "a.dat not $contents_oid" 168 ls -al 169 cat a.dat 170 exit 1 171 } 172 assert_local_object "$contents_oid" 173 174 git lfs pull | tee pull.txt 175 if [ "0" -ne "${PIPESTATUS[0]}" ]; then 176 echo >&2 "fatal: expected pull to succeed ..." 177 exit 1 178 fi 179 grep "Git LFS is not installed" pull.txt 180 echo "pulled!" 181 182 # LFS object downloaded, pointer unchanged 183 grep "$contents_oid" a.dat || { 184 echo "a.dat not $contents_oid" 185 ls -al 186 cat a.dat 187 exit 1 188 } 189 assert_local_object "$contents_oid" 1 190 ) 191 end_test 192 193 begin_test "pull with raw remote url" 194 ( 195 set -e 196 mkdir raw 197 cd raw 198 git init 199 git lfs install --local --skip-smudge 200 201 git remote add origin $GITSERVER/t-pull 202 git pull origin master 203 204 contents="a" 205 contents_oid=$(calc_oid "$contents") 206 207 # LFS object not downloaded, pointer in working directory 208 refute_local_object "$contents_oid" 209 grep "$contents_oid" a.dat 210 211 git lfs pull "$GITSERVER/t-pull" 212 echo "pulled!" 213 214 # LFS object downloaded and in working directory 215 assert_local_object "$contents_oid" 1 216 [ "0" = "$(grep -c "$contents_oid" a.dat)" ] 217 [ "a" = "$(cat a.dat)" ] 218 ) 219 end_test 220 221 begin_test "pull with multiple remotes" 222 ( 223 set -e 224 mkdir multiple 225 cd multiple 226 git init 227 git lfs install --local --skip-smudge 228 229 git remote add origin "$GITSERVER/t-pull" 230 git remote add bad-remote "invalid-url" 231 git pull origin master 232 233 contents="a" 234 contents_oid=$(calc_oid "$contents") 235 236 # LFS object not downloaded, pointer in working directory 237 refute_local_object "$contents_oid" 238 grep "$contents_oid" a.dat 239 240 # pull should default to origin instead of bad-remote 241 git lfs pull 242 echo "pulled!" 243 244 # LFS object downloaded and in working directory 245 assert_local_object "$contents_oid" 1 246 [ "0" = "$(grep -c "$contents_oid" a.dat)" ] 247 [ "a" = "$(cat a.dat)" ] 248 ) 249 end_test 250 251 begin_test "pull: with missing object" 252 ( 253 set -e 254 255 # this clone is setup in the first test in this file 256 cd clone 257 rm -rf .git/lfs/objects 258 259 contents_oid=$(calc_oid "a") 260 reponame="$(basename "$0" ".sh")" 261 delete_server_object "$reponame" "$contents_oid" 262 refute_server_object "$reponame" "$contents_oid" 263 264 # should return non-zero, but should also download all the other valid files too 265 git lfs pull 2>&1 | tee pull.log 266 pull_exit="${PIPESTATUS[0]}" 267 [ "$pull_exit" != "0" ] 268 269 grep "$contents_oid" pull.log 270 271 contents2_oid=$(calc_oid "A") 272 assert_local_object "$contents2_oid" 1 273 refute_local_object "$contents_oid" 274 ) 275 end_test 276 277 begin_test "pull: outside git repository" 278 ( 279 set +e 280 git lfs pull 2>&1 > pull.log 281 res=$? 282 283 set -e 284 if [ "$res" = "0" ]; then 285 echo "Passes because $GIT_LFS_TEST_DIR is unset." 286 exit 0 287 fi 288 [ "$res" = "128" ] 289 grep "Not in a git repository" pull.log 290 ) 291 end_test