Debian Codegraph @

t/t-fetch-recent.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/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\":[\"main\"],
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 main
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 main
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 main
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 # force color codes in git diff meta-information
109 git config color.diff always
110
111 git lfs fetch --recent origin
112 # that should have fetched main plus previous state needed within 7 days
113 # current state
114 assert_local_object "$oid2" "${#content2}"
115 assert_local_object "$oid3" "${#content3}"
116 # previous state is the 'before' state of any commits made in last 7 days
117 # ie you can check out anything in last 7 days (may have non-LFS commits in between)
118 assert_local_object "$oid1" "${#content1}"
119 refute_local_object "$oid0"
120 refute_local_object "$oid4"
121 )
122 end_test
123
124 begin_test "fetch-recent days"
125 (
126 set -e
127
128 cd clone
129 rm -rf .git/lfs/objects
130
131 # now fetch other_branch as well
132 git config lfs.fetchrecentrefsdays 6
133 git config lfs.fetchrecentremoterefs false
134 git config lfs.fetchrecentcommitsdays 7
135
136 git lfs fetch --recent origin
137 # that should have fetched main plus previous state needed within 7 days
138 # current state PLUS refs within 6 days (& their commits within 7)
139 assert_local_object "$oid2" "${#content2}"
140 assert_local_object "$oid3" "${#content3}"
141 assert_local_object "$oid1" "${#content1}"
142 assert_local_object "$oid4" "${#content4}"
143 # still omits oid0 since that's at best 13 days prior to other_branch tip
144 refute_local_object "$oid0"
145 )
146 end_test
147
148 begin_test "fetch-recent older commits"
149 (
150 set -e
151
152 cd clone
153 # now test that a 14 day limit picks oid0 up from other_branch
154 # because other_branch was itself 5 days ago, 5+14=19 day search limit
155 git config lfs.fetchrecentcommitsdays 14
156
157 rm -rf .git/lfs/objects
158 git lfs fetch --recent origin
159 assert_local_object "$oid0" "${#content0}"
160 )
161 end_test
162
163 begin_test "fetch-recent remote branch"
164 (
165 set -e
166
167 cd "$reponame"
168 # push branch & test remote branch recent
169 git push origin other_branch
170
171 cd ../clone
172 git branch -D other_branch
173 rm -rf .git/lfs/objects
174 git config lfs.fetchrecentcommitsdays 0
175 git config lfs.fetchrecentremoterefs false
176 git config lfs.fetchrecentrefsdays 6
177
178 git lfs fetch --recent origin
179 # should miss #4 until we include remote branches (#1 will always be missing commitdays=0)
180 assert_local_object "$oid2" "${#content2}"
181 assert_local_object "$oid3" "${#content3}"
182 refute_local_object "$oid1"
183 refute_local_object "$oid0"
184 refute_local_object "$oid4"
185 )
186 end_test
187
188 begin_test "fetch-recent remote refs"
189 (
190 set -e
191
192 cd clone
193 rm -rf .git/lfs/objects
194
195 # pick up just snapshot at remote ref, ie #4
196 git config lfs.fetchrecentremoterefs true
197 git lfs fetch --recent origin
198 assert_local_object "$oid4" "${#content4}"
199 refute_local_object "$oid0"
200 refute_local_object "$oid1"
201 )
202 end_test