2 # This is a sample Git LFS test. See test/README.md and testhelpers.sh for
5 . "$(dirname "$0")/testlib.sh"
7 begin_test "happy path"
11 # This initializes a new bare git repository in test/remote.
12 # These remote repositories are global to every test, so keep the names
14 reponame="$(basename "$0" ".sh")"
15 setup_remote_repo "$reponame"
17 # Clone the repository from the test Git server. This is empty, and will be
18 # used to test a "git pull" below. The repo is cloned to $TRASHDIR/clone
19 clone_repo "$reponame" clone
21 # Clone the repository again to $TRASHDIR/repo. This will be used to commit
23 clone_repo "$reponame" repo
25 # This executes Git LFS from the local repo that was just cloned.
26 git lfs track "*.dat" 2>&1 | tee track.log
27 grep "Tracking \"\*.dat\"" track.log
30 contents_oid=$(calc_oid "$contents")
32 # Regular Git commands can be used.
33 printf "$contents" > a.dat
35 git add .gitattributes
36 git commit -m "add a.dat" 2>&1 | tee commit.log
37 grep "master (root-commit)" commit.log
38 grep "2 files changed" commit.log
39 grep "create mode 100644 a.dat" commit.log
40 grep "create mode 100644 .gitattributes" commit.log
42 [ "a" = "$(cat a.dat)" ]
44 # This is a small shell function that runs several git commands together.
45 assert_pointer "master" "a.dat" "$contents_oid" 1
47 refute_server_object "$reponame" "$contents_oid"
49 # This pushes to the remote repository set up at the top of the test.
50 git push origin master 2>&1 | tee push.log
51 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
52 grep "master -> master" push.log
54 assert_server_object "$reponame" "$contents_oid"
56 # change to the clone's working directory
61 [ "a" = "$(cat a.dat)" ]
63 assert_pointer "master" "a.dat" "$contents_oid" 1
67 begin_test "happy path on non-origin remote"
71 reponame="happy-without-origin"
72 setup_remote_repo "$reponame"
74 clone_repo "$reponame" repo-without-origin
76 git add .gitattributes
78 git push origin master
80 clone_repo "$reponame" clone-without-origin
81 git remote rename origin happy-path
83 cd ../repo-without-origin
87 git push origin master
89 cd ../clone-without-origin
92 git pull happy-path master
96 begin_test "happy path on good ref"
100 reponame="happy-path-master-branch-required"
101 setup_remote_repo "$reponame"
102 clone_repo "$reponame" "$reponame"
104 git lfs track "*.dat"
106 git add .gitattributes a.dat
107 git commit -m "add a.dat"
109 git push origin master
111 # $ echo "a" | shasum -a 256
112 oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
113 assert_local_object "$oid" 2
114 assert_server_object "$reponame" "$oid" "refs/heads/master"
116 clone_repo "$reponame" "$reponame-clone"
117 assert_local_object "$oid" 2
121 begin_test "happy path on tracked ref"
125 reponame="happy-path-tracked-branch-required"
126 setup_remote_repo "$reponame"
127 clone_repo "$reponame" "$reponame"
129 git lfs track "*.dat"
131 git add .gitattributes a.dat
132 git commit -m "add a.dat"
134 git push origin master:tracked
136 # $ echo "a" | shasum -a 256
137 oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
138 assert_local_object "$oid" 2
139 assert_server_object "$reponame" "$oid" "refs/heads/tracked"
141 git lfs clone "$GITSERVER/$reponame" --exclude "*"
143 git config credential.helper lfstest
144 git config push.default upstream
145 git config branch.master.merge refs/heads/tracked
148 assert_local_object "$oid" 2
152 begin_test "clears local temp objects"
156 mkdir repo-temp-objects
160 # abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
161 mkdir -p .git/lfs/objects/go/od
162 mkdir -p .git/lfs/tmp/objects
164 touch .git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx
165 touch .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123
166 touch .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456
167 touch .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123
168 touch .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456
170 GIT_TRACE=5 git lfs env
173 [ -e ".git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx" ]
175 # newer tmp files exist
176 [ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123" ]
177 [ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456" ]
179 # existing tmp files were cleaned up
180 [ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123" ]
181 [ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456" ]