Imported Upstream version 2.5.1
[scm/test.git] / t / t-custom-transfers.sh
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "custom-transfer-wrong-path"
6 (
7   set -e
8
9   # this repo name is the indicator to the server to support custom transfer
10   reponame="test-custom-transfer-fail"
11   setup_remote_repo "$reponame"
12
13   clone_repo "$reponame" $reponame
14
15   # deliberately incorrect path
16   git config lfs.customtransfer.testcustom.path path-to-nothing
17
18   git lfs track "*.dat" 2>&1 | tee track.log
19   grep "Tracking \"\*.dat\"" track.log
20
21   contents="jksgdfljkgsdlkjafg lsjdgf alkjgsd lkfjag sldjkgf alkjsgdflkjagsd kljfg asdjgf kalsd"
22   contents_oid=$(calc_oid "$contents")
23
24   printf "$contents" > a.dat
25   git add a.dat
26   git add .gitattributes
27   git commit -m "add a.dat" 2>&1 | tee commit.log
28   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushcustom.log
29   # use PIPESTATUS otherwise we get exit code from tee
30   res=${PIPESTATUS[0]}
31   grep "xfer: adapter \"testcustom\" Begin()" pushcustom.log
32   grep "Failed to start custom transfer command" pushcustom.log
33   if [ "$res" = "0" ]; then
34     echo "Push should have failed because of an incorrect custom transfer path."
35     exit 1
36   fi
37
38 )
39 end_test
40
41 begin_test "custom-transfer-upload-download"
42 (
43   set -e
44
45   # this repo name is the indicator to the server to support custom transfer
46   reponame="test-custom-transfer-1"
47   setup_remote_repo "$reponame"
48
49   clone_repo "$reponame" $reponame
50
51   # set up custom transfer adapter
52   git config lfs.customtransfer.testcustom.path lfstest-customadapter
53
54   git lfs track "*.dat" 2>&1 | tee track.log
55   grep "Tracking \"\*.dat\"" track.log
56   git add .gitattributes
57   git commit -m "Tracking"
58
59   # set up a decent amount of data so that there's work for multiple concurrent adapters
60   echo "[
61   {
62     \"CommitDate\":\"$(get_date -10d)\",
63     \"Files\":[
64       {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
65       {\"Filename\":\"file1.dat\",\"Size\":1024},
66       {\"Filename\":\"file2.dat\",\"Size\":750}]
67   },
68   {
69     \"CommitDate\":\"$(get_date -7d)\",
70     \"Files\":[
71       {\"Filename\":\"file1.dat\",\"Size\":1050},
72       {\"Filename\":\"file3.dat\",\"Size\":660},
73       {\"Filename\":\"file4.dat\",\"Size\":230}]
74   },
75   {
76     \"CommitDate\":\"$(get_date -5d)\",
77     \"Files\":[
78       {\"Filename\":\"file5.dat\",\"Size\":1200},
79       {\"Filename\":\"file6.dat\",\"Size\":300}]
80   },
81   {
82     \"CommitDate\":\"$(get_date -2d)\",
83     \"Files\":[
84       {\"Filename\":\"file3.dat\",\"Size\":120},
85       {\"Filename\":\"file5.dat\",\"Size\":450},
86       {\"Filename\":\"file7.dat\",\"Size\":520},
87       {\"Filename\":\"file8.dat\",\"Size\":2048}]
88   }
89   ]" | lfstest-testutils addcommits
90
91   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushcustom.log
92   # use PIPESTATUS otherwise we get exit code from tee
93   [ ${PIPESTATUS[0]} = "0" ]
94
95   grep "xfer: started custom adapter process" pushcustom.log
96   grep "xfer\[lfstest-customadapter\]:" pushcustom.log
97   grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
98
99   rm -rf .git/lfs/objects
100   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all  2>&1 | tee fetchcustom.log
101   [ ${PIPESTATUS[0]} = "0" ]
102
103   grep "xfer: started custom adapter process" fetchcustom.log
104   grep "xfer\[lfstest-customadapter\]:" fetchcustom.log
105
106   grep "Terminating test custom adapter gracefully" fetchcustom.log
107
108   objectlist=`find .git/lfs/objects -type f`
109   [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
110 )
111 end_test
112
113 begin_test "custom-transfer-standalone"
114 (
115   set -e
116
117   # setup a git repo to be used as a local repo, not remote
118   reponame="test-custom-transfer-standalone"
119   setup_remote_repo "$reponame"
120
121   # clone directly, not through lfstest-gitserver
122   clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
123
124   # set up custom transfer adapter to use a specific transfer agent
125   git config lfs.customtransfer.testcustom.path lfstest-standalonecustomadapter
126   git config lfs.customtransfer.testcustom.concurrent false
127   git config lfs.standalonetransferagent testcustom
128   export TEST_STANDALONE_BACKUP_PATH="$(pwd)/test-custom-transfer-standalone-backup"
129   mkdir -p $TEST_STANDALONE_BACKUP_PATH
130   rm -rf $TEST_STANDALONE_BACKUP_PATH/*
131
132   git lfs track "*.dat" 2>&1 | tee track.log
133   grep "Tracking \"\*.dat\"" track.log
134   git add .gitattributes
135   git commit -m "Tracking"
136
137   # set up a decent amount of data so that there's work for multiple concurrent adapters
138   echo "[
139   {
140     \"CommitDate\":\"$(get_date -10d)\",
141     \"Files\":[
142       {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
143       {\"Filename\":\"file1.dat\",\"Size\":1024},
144       {\"Filename\":\"file2.dat\",\"Size\":750}]
145   },
146   {
147     \"CommitDate\":\"$(get_date -7d)\",
148     \"Files\":[
149       {\"Filename\":\"file1.dat\",\"Size\":1050},
150       {\"Filename\":\"file3.dat\",\"Size\":660},
151       {\"Filename\":\"file4.dat\",\"Size\":230}]
152   },
153   {
154     \"CommitDate\":\"$(get_date -5d)\",
155     \"Files\":[
156       {\"Filename\":\"file5.dat\",\"Size\":1200},
157       {\"Filename\":\"file6.dat\",\"Size\":300}]
158   },
159   {
160     \"CommitDate\":\"$(get_date -2d)\",
161     \"Files\":[
162       {\"Filename\":\"file3.dat\",\"Size\":120},
163       {\"Filename\":\"file5.dat\",\"Size\":450},
164       {\"Filename\":\"file7.dat\",\"Size\":520},
165       {\"Filename\":\"file8.dat\",\"Size\":2048}]
166   }
167   ]" | lfstest-testutils addcommits
168
169   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushcustom.log
170   # use PIPESTATUS otherwise we get exit code from tee
171   [ ${PIPESTATUS[0]} = "0" ]
172
173   # Make sure the lock verification is not attempted.
174   grep "locks/verify$" pushcustom.log && false
175
176   grep "xfer: started custom adapter process" pushcustom.log
177   grep "xfer\[lfstest-standalonecustomadapter\]:" pushcustom.log
178   grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
179
180   rm -rf .git/lfs/objects
181   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all  2>&1 | tee fetchcustom.log
182   [ ${PIPESTATUS[0]} = "0" ]
183
184   grep "xfer: started custom adapter process" fetchcustom.log
185   grep "xfer\[lfstest-standalonecustomadapter\]:" fetchcustom.log
186   grep "Downloading LFS objects: 100% (12/12)" fetchcustom.log
187
188   grep "Terminating test custom adapter gracefully" fetchcustom.log
189
190   objectlist=`find .git/lfs/objects -type f`
191   [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
192 )
193 end_test
194
195 begin_test "custom-transfer-standalone-urlmatch"
196 (
197   set -e
198
199   # setup a git repo to be used as a local repo, not remote
200   reponame="test-custom-transfer-standalone-urlmatch"
201   setup_remote_repo "$reponame"
202
203   # clone directly, not through lfstest-gitserver
204   clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
205
206   # set up custom transfer adapter to use a specific transfer agent, using a URL prefix match
207   git config lfs.customtransfer.testcustom.path lfstest-standalonecustomadapter
208   git config lfs.customtransfer.testcustom.concurrent false
209   git config remote.origin.lfsurl https://git.example.com/example/path/to/repo
210   git config lfs.https://git.example.com/example/path/.standalonetransferagent testcustom
211   git config lfs.standalonetransferagent invalid-agent
212
213   # git config lfs.standalonetransferagent testcustom
214   export TEST_STANDALONE_BACKUP_PATH="$(pwd)/test-custom-transfer-standalone-urlmatch-backup"
215   mkdir -p $TEST_STANDALONE_BACKUP_PATH
216   rm -rf $TEST_STANDALONE_BACKUP_PATH/*
217
218   git lfs track "*.dat" 2>&1 | tee track.log
219   grep "Tracking \"\*.dat\"" track.log
220   git add .gitattributes
221   git commit -m "Tracking"
222
223   # set up a decent amount of data so that there's work for multiple concurrent adapters
224   echo "[
225   {
226     \"CommitDate\":\"$(get_date -10d)\",
227     \"Files\":[
228       {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
229       {\"Filename\":\"file1.dat\",\"Size\":1024},
230       {\"Filename\":\"file2.dat\",\"Size\":750}]
231   },
232   {
233     \"CommitDate\":\"$(get_date -7d)\",
234     \"Files\":[
235       {\"Filename\":\"file1.dat\",\"Size\":1050},
236       {\"Filename\":\"file3.dat\",\"Size\":660},
237       {\"Filename\":\"file4.dat\",\"Size\":230}]
238   },
239   {
240     \"CommitDate\":\"$(get_date -5d)\",
241     \"Files\":[
242       {\"Filename\":\"file5.dat\",\"Size\":1200},
243       {\"Filename\":\"file6.dat\",\"Size\":300}]
244   },
245   {
246     \"CommitDate\":\"$(get_date -2d)\",
247     \"Files\":[
248       {\"Filename\":\"file3.dat\",\"Size\":120},
249       {\"Filename\":\"file5.dat\",\"Size\":450},
250       {\"Filename\":\"file7.dat\",\"Size\":520},
251       {\"Filename\":\"file8.dat\",\"Size\":2048}]
252   }
253   ]" | lfstest-testutils addcommits
254
255   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushcustom.log
256   # use PIPESTATUS otherwise we get exit code from tee
257   [ ${PIPESTATUS[0]} = "0" ]
258
259   # Make sure the lock verification is not attempted.
260   grep "locks/verify$" pushcustom.log && false
261
262   grep "xfer: started custom adapter process" pushcustom.log
263   grep "xfer\[lfstest-standalonecustomadapter\]:" pushcustom.log
264   grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
265
266   rm -rf .git/lfs/objects
267   GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all  2>&1 | tee fetchcustom.log
268   [ ${PIPESTATUS[0]} = "0" ]
269
270   grep "xfer: started custom adapter process" fetchcustom.log
271   grep "xfer\[lfstest-standalonecustomadapter\]:" fetchcustom.log
272   grep "Downloading LFS objects: 100% (12/12)" fetchcustom.log
273
274   grep "Terminating test custom adapter gracefully" fetchcustom.log
275
276   objectlist=`find .git/lfs/objects -type f`
277   [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
278 )
279 end_test