Imported Upstream version 2.5.1
[scm/test.git] / t / t-happy-path.sh
1 #!/usr/bin/env bash
2 # This is a sample Git LFS test.  See test/README.md and testhelpers.sh for
3 # more documentation.
4
5 . "$(dirname "$0")/testlib.sh"
6
7 begin_test "happy path"
8 (
9   set -e
10
11   # This initializes a new bare git repository in test/remote.
12   # These remote repositories are global to every test, so keep the names
13   # unique.
14   reponame="$(basename "$0" ".sh")"
15   setup_remote_repo "$reponame"
16
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
20
21   # Clone the repository again to $TRASHDIR/repo. This will be used to commit
22   # and push objects.
23   clone_repo "$reponame" repo
24
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
28
29   contents="a"
30   contents_oid=$(calc_oid "$contents")
31
32   # Regular Git commands can be used.
33   printf "$contents" > a.dat
34   git add 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
41
42   [ "a" = "$(cat a.dat)" ]
43
44   # This is a small shell function that runs several git commands together.
45   assert_pointer "master" "a.dat" "$contents_oid" 1
46
47   refute_server_object "$reponame" "$contents_oid"
48
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
53
54   assert_server_object "$reponame" "$contents_oid"
55
56   # change to the clone's working directory
57   cd ../clone
58
59   git pull
60
61   [ "a" = "$(cat a.dat)" ]
62
63   assert_pointer "master" "a.dat" "$contents_oid" 1
64 )
65 end_test
66
67 begin_test "happy path on non-origin remote"
68 (
69   set -e
70
71   reponame="happy-without-origin"
72   setup_remote_repo "$reponame"
73
74   clone_repo "$reponame" repo-without-origin
75   git lfs track "*.dat"
76   git add .gitattributes
77   git commit -m "track"
78   git push origin master
79
80   clone_repo "$reponame" clone-without-origin
81   git remote rename origin happy-path
82
83   cd ../repo-without-origin
84   echo "a" > a.dat
85   git add a.dat
86   git commit -m "boom"
87   git push origin master
88
89   cd ../clone-without-origin
90   echo "remotes:"
91   git remote
92   git pull happy-path master
93 )
94 end_test
95
96 begin_test "happy path on good ref"
97 (
98   set -e
99
100   reponame="happy-path-master-branch-required"
101   setup_remote_repo "$reponame"
102   clone_repo "$reponame" "$reponame"
103
104   git lfs track "*.dat"
105   echo "a" > a.dat
106   git add .gitattributes a.dat
107   git commit -m "add a.dat"
108
109   git push origin master
110
111   # $ echo "a" | shasum -a 256
112   oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
113   assert_local_object "$oid" 2
114   assert_server_object "$reponame" "$oid" "refs/heads/master"
115
116   clone_repo "$reponame" "$reponame-clone"
117   assert_local_object "$oid" 2
118 )
119 end_test
120
121 begin_test "happy path on tracked ref"
122 (
123   set -e
124
125   reponame="happy-path-tracked-branch-required"
126   setup_remote_repo "$reponame"
127   clone_repo "$reponame" "$reponame"
128
129   git lfs track "*.dat"
130   echo "a" > a.dat
131   git add .gitattributes a.dat
132   git commit -m "add a.dat"
133
134   git push origin master:tracked
135
136   # $ echo "a" | shasum -a 256
137   oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
138   assert_local_object "$oid" 2
139   assert_server_object "$reponame" "$oid" "refs/heads/tracked"
140
141   git lfs clone "$GITSERVER/$reponame" --exclude "*"
142
143   git config credential.helper lfstest
144   git config push.default upstream
145   git config branch.master.merge refs/heads/tracked
146
147   git checkout
148   assert_local_object "$oid" 2
149 )
150 end_test
151
152 begin_test "clears local temp objects"
153 (
154   set -e
155
156   mkdir repo-temp-objects
157   cd repo-temp-objects
158   git init
159
160   # abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
161   mkdir -p .git/lfs/objects/go/od
162   mkdir -p .git/lfs/tmp/objects
163
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
169
170   GIT_TRACE=5 git lfs env
171
172   # object file exists
173   [ -e ".git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx" ]
174
175   # newer tmp files exist
176   [ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123" ]
177   [ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456" ]
178
179   # existing tmp files were cleaned up
180   [ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123" ]
181   [ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456" ]
182 )
183 end_test