5ade93c717cd730630e3c7d2f54ae938188ae9ff
[scm/test.git] / test / test-fetch-recent.sh
1 #!/usr/bin/env bash
2
3 . "test/testlib.sh"
4
5 reponame="fetch-recent"
6
7 # generate content we'll use
8 content0="filecontent0"
9 content1="filecontent1"
10 content2="filecontent2"
11 content3="filecontent3"
12 content4="filecontent4"
13 content5="filecontent5"
14 oid0=$(calc_oid "$content0")
15 oid1=$(calc_oid "$content1")
16 oid2=$(calc_oid "$content2")
17 oid3=$(calc_oid "$content3")
18 oid4=$(calc_oid "$content4")
19 oid5=$(calc_oid "$content5")
20
21 begin_test "init fetch-recent"
22 (
23   set -e
24
25   setup_remote_repo "$reponame"
26   clone_repo "$reponame" "$reponame"
27
28   git lfs track "*.dat" 2>&1 | tee track.log
29   grep "Tracking \"\*.dat\"" track.log
30
31   echo "[
32   {
33     \"CommitDate\":\"$(get_date -18d)\",
34     \"Files\":[
35       {\"Filename\":\"file1.dat\",\"Size\":${#content0}, \"Data\":\"$content0\"},
36       {\"Filename\":\"file3.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
37   },
38   {
39     \"CommitDate\":\"$(get_date -14d)\",
40     \"Files\":[
41       {\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
42   },
43   {
44     \"CommitDate\":\"$(get_date -5d)\",
45     \"NewBranch\":\"other_branch\",
46     \"Files\":[
47       {\"Filename\":\"file1.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
48   },
49   {
50     \"CommitDate\":\"$(get_date -1d)\",
51     \"ParentBranches\":[\"master\"],
52     \"Files\":[
53       {\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"},
54       {\"Filename\":\"file2.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"}]
55   }
56   ]" | lfstest-testutils addcommits
57
58   git push origin master
59   git push origin other_branch
60   assert_server_object "$reponame" "$oid0"
61   assert_server_object "$reponame" "$oid1"
62   assert_server_object "$reponame" "$oid2"
63   assert_server_object "$reponame" "$oid3"
64   assert_server_object "$reponame" "$oid4"
65
66   # This clone is used for subsequent tests
67   clone_repo "$reponame" clone
68   git checkout other_branch
69   git checkout master
70 )
71 end_test
72
73 begin_test "fetch-recent normal"
74 (
75   set -e
76
77   cd clone
78   rm -rf .git/lfs/objects
79
80   git config lfs.fetchrecentalways false
81   git config lfs.fetchrecentrefsdays 0
82   git config lfs.fetchrecentremoterefs false
83   git config lfs.fetchrecentcommitsdays 7
84
85   # fetch normally, should just get the last state for file1/2
86   git lfs fetch origin master
87   assert_local_object "$oid2" "${#content2}"
88   assert_local_object "$oid3" "${#content3}"
89   assert_local_object "$oid5" "${#content5}"
90   refute_local_object "$oid0"
91   refute_local_object "$oid1"
92   refute_local_object "$oid4"
93 )
94 end_test
95
96 begin_test "fetch-recent commits"
97 (
98   set -e
99
100   cd clone
101   rm -rf .git/lfs/objects
102
103   # now fetch recent - just commits for now
104   git config lfs.fetchrecentrefsdays 0
105   git config lfs.fetchrecentremoterefs false
106   git config lfs.fetchrecentcommitsdays 7
107
108   git lfs fetch --recent origin
109   # that should have fetched master plus previous state needed within 7 days
110   # current state
111   assert_local_object "$oid2" "${#content2}"
112   assert_local_object "$oid3" "${#content3}"
113   # previous state is the 'before' state of any commits made in last 7 days
114   # ie you can check out anything in last 7 days (may have non-LFS commits in between)
115   assert_local_object "$oid1" "${#content1}"
116   refute_local_object "$oid0"
117   refute_local_object "$oid4"
118 )
119 end_test
120
121 begin_test "fetch-recent days"
122 (
123   set -e
124
125   cd clone
126   rm -rf .git/lfs/objects
127
128   # now fetch other_branch as well
129   git config lfs.fetchrecentrefsdays 6
130   git config lfs.fetchrecentremoterefs false
131   git config lfs.fetchrecentcommitsdays 7
132
133   git lfs fetch --recent origin
134   # that should have fetched master plus previous state needed within 7 days
135   # current state PLUS refs within 6 days (& their commits within 7)
136   assert_local_object "$oid2" "${#content2}"
137   assert_local_object "$oid3" "${#content3}"
138   assert_local_object "$oid1" "${#content1}"
139   assert_local_object "$oid4" "${#content4}"
140   # still omits oid0 since that's at best 13 days prior to other_branch tip
141   refute_local_object "$oid0"
142 )
143 end_test
144
145 begin_test "fetch-recent older commits"
146 (
147   set -e
148
149   cd clone
150   # now test that a 14 day limit picks oid0 up from other_branch
151   # because other_branch was itself 5 days ago, 5+14=19 day search limit
152   git config lfs.fetchrecentcommitsdays 14
153
154   rm -rf .git/lfs/objects
155   git lfs fetch --recent origin
156   assert_local_object "$oid0" "${#content0}"
157 )
158 end_test
159
160 begin_test "fetch-recent remote branch"
161 (
162   set -e
163
164   cd "$reponame"
165   # push branch & test remote branch recent
166   git push origin other_branch
167
168   cd ../clone
169   git branch -D other_branch
170   rm -rf .git/lfs/objects
171   git config lfs.fetchrecentcommitsdays 0
172   git config lfs.fetchrecentremoterefs false
173   git config lfs.fetchrecentrefsdays 6
174
175   git lfs fetch --recent origin
176   # should miss #4 until we include remote branches (#1 will always be missing commitdays=0)
177   assert_local_object "$oid2" "${#content2}"
178   assert_local_object "$oid3" "${#content3}"
179   refute_local_object "$oid1"
180   refute_local_object "$oid0"
181   refute_local_object "$oid4"
182 )
183 end_test
184
185 begin_test "fetch-recent remote refs"
186 (
187   set -e
188
189   cd clone
190   rm -rf .git/lfs/objects
191
192   # pick up just snapshot at remote ref, ie #4
193   git config lfs.fetchrecentremoterefs true
194   git lfs fetch --recent origin
195   assert_local_object "$oid4" "${#content4}"
196   refute_local_object "$oid0"
197   refute_local_object "$oid1"
198 )
199 end_test