Imported Upstream version 2.5.1
[scm/test.git] / t / t-batch-transfer.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 "batch transfer"
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   reponame1="$(basename "$0" ".sh")"
15   reponame2="CAPITALLETTERS"
16   reponame=$reponame1$reponame2
17   setup_remote_repo "$reponame"
18
19   # Clone the repository from the test Git server.  This is empty, and will be
20   # used to test a "git pull" below. The repo is cloned to $TRASHDIR/clone
21   clone_repo "$reponame" clone
22
23   # Clone the repository again to $TRASHDIR/repo. This will be used to commit
24   # and push objects.
25   clone_repo "$reponame" repo
26
27   # This executes Git LFS from the local repo that was just cloned.
28   git lfs track "*.dat" 2>&1 | tee track.log
29   grep "Tracking \"\*.dat\"" track.log
30
31   contents="a"
32   contents_oid=$(calc_oid "$contents")
33
34   printf "$contents" > a.dat
35   git add a.dat
36   git add .gitattributes
37   git commit -m "add a.dat" 2>&1 | tee commit.log
38   grep "master (root-commit)" commit.log
39   grep "2 files changed" commit.log
40   grep "create mode 100644 a.dat" commit.log
41   grep "create mode 100644 .gitattributes" commit.log
42
43   [ "a" = "$(cat a.dat)" ]
44
45   # This is a small shell function that runs several git commands together.
46   assert_pointer "master" "a.dat" "$contents_oid" 1
47
48   refute_server_object "$reponame" "$contents_oid"
49
50   # This pushes to the remote repository set up at the top of the test.
51   git push origin master 2>&1 | tee push.log
52   grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
53   grep "master -> master" push.log
54
55   assert_server_object "$reponame" "$contents_oid"
56
57   # change to the clone's working directory
58   cd ../clone
59
60   git pull
61
62   [ "a" = "$(cat a.dat)" ]
63
64   assert_pointer "master" "a.dat" "$contents_oid" 1
65 )
66 end_test
67
68 begin_test "batch transfers occur in reverse order by size"
69 (
70   set -e
71
72   reponame="batch-order-test"
73   setup_remote_repo "$reponame"
74   clone_repo "$reponame" "$reponame"
75
76   git lfs track "*.dat"
77   git add .gitattributes
78   git commit -m "initial commit"
79
80   small_contents="small"
81   small_oid="$(calc_oid "$small_contents")"
82   printf "$small_contents" > small.dat
83
84   bigger_contents="bigger"
85   bigger_oid="$(calc_oid "$bigger_contents")"
86   printf "$bigger_contents" > bigger.dat
87
88   git add *.dat
89   git commit -m "add small and large objects"
90
91   GIT_CURL_VERBOSE=1 git push origin master 2>&1 | tee push.log
92
93   batch="$(grep "{\"operation\":\"upload\"" push.log | head -1)"
94
95   pos_small="$(substring_position "$batch" "$small_oid")"
96   pos_large="$(substring_position "$batch" "$bigger_oid")"
97
98   # Assert that the the larger object shows up earlier in the batch than the
99   # smaller object
100   [ "$pos_large" -lt "$pos_small" ]
101 )
102 end_test
103
104 begin_test "batch transfers with ssh endpoint"
105 (
106   set -e
107
108   reponame="batch-ssh"
109   setup_remote_repo "$reponame"
110   clone_repo "$reponame" "$reponame"
111
112   sshurl="${GITSERVER/http:\/\//ssh://git@}/$reponame"
113   git config lfs.url "$sshurl"
114   git lfs env
115
116   contents="test"
117   oid="$(calc_oid "$contents")"
118   git lfs track "*.dat"
119   printf "$contents" > test.dat
120   git add .gitattributes test.dat
121   git commit -m "initial commit"
122
123   git push origin master 2>&1
124 )
125 end_test
126
127 begin_test "batch transfers with ntlm server"
128 (
129   set -e
130
131   reponame="ntlmtest"
132   setup_remote_repo "$reponame"
133
134   printf "ntlmdomain\\\ntlmuser:ntlmpass" > "$CREDSDIR/127.0.0.1--$reponame"
135
136   clone_repo "$reponame" "$reponame"
137
138   contents="test"
139   oid="$(calc_oid "$contents")"
140   git lfs track "*.dat"
141   printf "$contents" > test.dat
142   git add .gitattributes test.dat
143   git commit -m "initial commit"
144
145   GIT_CURL_VERBOSE=1 git push origin master 2>&1
146 )
147 end_test