5 reponame="fetch-recent"
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")
21 begin_test "init fetch-recent"
25 setup_remote_repo "$reponame"
26 clone_repo "$reponame" "$reponame"
28 git lfs track "*.dat" 2>&1 | tee track.log
29 grep "Tracking \"\*.dat\"" track.log
33 \"CommitDate\":\"$(get_date -18d)\",
35 {\"Filename\":\"file1.dat\",\"Size\":${#content0}, \"Data\":\"$content0\"},
36 {\"Filename\":\"file3.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
39 \"CommitDate\":\"$(get_date -14d)\",
41 {\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
44 \"CommitDate\":\"$(get_date -5d)\",
45 \"NewBranch\":\"other_branch\",
47 {\"Filename\":\"file1.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
50 \"CommitDate\":\"$(get_date -1d)\",
51 \"ParentBranches\":[\"master\"],
53 {\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"},
54 {\"Filename\":\"file2.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"}]
56 ]" | lfstest-testutils addcommits
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"
66 # This clone is used for subsequent tests
67 clone_repo "$reponame" clone
68 git checkout other_branch
73 begin_test "fetch-recent normal"
78 rm -rf .git/lfs/objects
80 git config lfs.fetchrecentalways false
81 git config lfs.fetchrecentrefsdays 0
82 git config lfs.fetchrecentremoterefs false
83 git config lfs.fetchrecentcommitsdays 7
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"
96 begin_test "fetch-recent commits"
101 rm -rf .git/lfs/objects
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
108 git lfs fetch --recent origin
109 # that should have fetched master plus previous state needed within 7 days
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"
121 begin_test "fetch-recent days"
126 rm -rf .git/lfs/objects
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
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"
145 begin_test "fetch-recent older commits"
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
154 rm -rf .git/lfs/objects
155 git lfs fetch --recent origin
156 assert_local_object "$oid0" "${#content0}"
160 begin_test "fetch-recent remote branch"
165 # push branch & test remote branch recent
166 git push origin other_branch
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
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"
185 begin_test "fetch-recent remote refs"
190 rm -rf .git/lfs/objects
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"