core.fsyncmethod: tests for batch mode

Add test cases to exercise batch mode for: * 'git add' * 'git stash' * 'git update-index' * 'git unpack-objects' These tests ensure that the added data winds up in the object database. In this change we introduce a new test helper lib-unique-files.sh. The goal of this library is to create a tree of files that have different oids from any other files that may have been created in the current test repo. This helps us avoid missing validation of an object being added due to it already being in the repo. Signed-off-by: Neeraj Singh <neerajsi@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Neeraj Singh committed Apr 4, 2022 at 22:20 UTC d42bab442d7ca6bcc38aefe384e94d4320565b77
4 files changed +109 -14
t/lib-unique-files.sh new
+34
@@ -0,0 +1,34 @@
1 +# Helper to create files with unique contents
2 +
3 +# Create multiple files with unique contents within this test run. Takes the
4 +# number of directories, the number of files in each directory, and the base
5 +# directory.
6 +#
7 +# test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files
8 +# each in my_dir, all with contents
9 +# different from previous invocations
10 +# of this command in this run.
11 +
12 +test_create_unique_files () {
13 + test "$#" -ne 3 && BUG "3 param"
14 +
15 + local dirs="$1" &&
16 + local files="$2" &&
17 + local basedir="$3" &&
18 + local counter="0" &&
19 + local i &&
20 + local j &&
21 + test_tick &&
22 + local basedata="$basedir$test_tick" &&
23 + rm -rf "$basedir" &&
24 + for i in $(test_seq $dirs)
25 + do
26 + local dir="$basedir/dir$i" &&
27 + mkdir -p "$dir" &&
28 + for j in $(test_seq $files)
29 + do
30 + counter=$((counter + 1)) &&
31 + echo "$basedata.$counter">"$dir/file$j.txt"
32 + done
33 + done
34 +}
t/t3700-add.sh
+28
@@ -8,6 +8,8 @@ test_description='Test of git add, including the -- option.'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 +. $TEST_DIRECTORY/lib-unique-files.sh
12 +
13 # Test the file mode "$1" of the file "$2" in the index.
14 test_mode_in_index () {
15 case "$(git ls-files -s "$2")" in
@@ -34,6 +36,32 @@ test_expect_success \
36 'Test that "git add -- -q" works' \
37 'touch -- -q && git add -- -q'
38
39 +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
40 +
41 +test_expect_success 'git add: core.fsyncmethod=batch' "
42 + test_create_unique_files 2 4 files_base_dir1 &&
43 + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION add -- ./files_base_dir1/ &&
44 + git ls-files --stage files_base_dir1/ |
45 + test_parse_ls_files_stage_oids >added_files_oids &&
46 +
47 + # We created 2 subdirs with 4 files each (8 files total) above
48 + test_line_count = 8 added_files_oids &&
49 + git cat-file --batch-check='%(objectname)' <added_files_oids >added_files_actual &&
50 + test_cmp added_files_oids added_files_actual
51 +"
52 +
53 +test_expect_success 'git update-index: core.fsyncmethod=batch' "
54 + test_create_unique_files 2 4 files_base_dir2 &&
55 + find files_base_dir2 ! -type d -print | xargs git $BATCH_CONFIGURATION update-index --add -- &&
56 + git ls-files --stage files_base_dir2 |
57 + test_parse_ls_files_stage_oids >added_files2_oids &&
58 +
59 + # We created 2 subdirs with 4 files each (8 files total) above
60 + test_line_count = 8 added_files2_oids &&
61 + git cat-file --batch-check='%(objectname)' <added_files2_oids >added_files2_actual &&
62 + test_cmp added_files2_oids added_files2_actual
63 +"
64 +
65 test_expect_success \
66 'git add: Test that executable bit is not used if core.filemode=0' \
67 'git config core.filemode 0 &&
t/t3903-stash.sh
+20
@@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12 +. $TEST_DIRECTORY/lib-unique-files.sh
13
14 test_expect_success 'usage on cmd and subcommand invalid option' '
15 test_expect_code 129 git stash --invalid-option 2>usage &&
@@ -1336,6 +1337,25 @@ test_expect_success 'stash handles skip-worktree entries nicely' '
1337 git rev-parse --verify refs/stash:A.t
1338 '
1339
1340 +
1341 +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
1342 +
1343 +test_expect_success 'stash with core.fsyncmethod=batch' "
1344 + test_create_unique_files 2 4 files_base_dir &&
1345 + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION stash push -u -- ./files_base_dir/ &&
1346 +
1347 + # The files were untracked, so use the third parent,
1348 + # which contains the untracked files
1349 + git ls-tree -r stash^3 -- ./files_base_dir/ |
1350 + test_parse_ls_tree_oids >stashed_files_oids &&
1351 +
1352 + # We created 2 dirs with 4 files each (8 files total) above
1353 + test_line_count = 8 stashed_files_oids &&
1354 + git cat-file --batch-check='%(objectname)' <stashed_files_oids >stashed_files_actual &&
1355 + test_cmp stashed_files_oids stashed_files_actual
1356 +"
1357 +
1358 +
1359 test_expect_success 'git stash succeeds despite directory/file change' '
1360 test_create_repo directory_file_switch_v1 &&
1361 (
t/t5300-pack-object.sh
+27 -14
@@ -161,22 +161,27 @@ test_expect_success 'pack-objects with bogus arguments' '
161 '
162
163 check_unpack () {
164 + local packname="$1" &&
165 + local object_list="$2" &&
166 + local git_config="$3" &&
167 test_when_finished "rm -rf git2" &&
165 - git init --bare git2 &&
166 - git -C git2 unpack-objects -n <"$1".pack &&
167 - git -C git2 unpack-objects <"$1".pack &&
168 - (cd .git && find objects -type f -print) |
169 - while read path
170 - do
171 - cmp git2/$path .git/$path || {
172 - echo $path differs.
173 - return 1
174 - }
175 - done
168 + git $git_config init --bare git2 &&
169 + (
170 + git $git_config -C git2 unpack-objects -n <"$packname".pack &&
171 + git $git_config -C git2 unpack-objects <"$packname".pack &&
172 + git $git_config -C git2 cat-file --batch-check="%(objectname)"
173 + ) <"$object_list" >current &&
174 + cmp "$object_list" current
175 }
176
177 test_expect_success 'unpack without delta' '
179 - check_unpack test-1-${packname_1}
178 + check_unpack test-1-${packname_1} obj-list
179 +'
180 +
181 +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
182 +
183 +test_expect_success 'unpack without delta (core.fsyncmethod=batch)' '
184 + check_unpack test-1-${packname_1} obj-list "$BATCH_CONFIGURATION"
185 '
186
187 test_expect_success 'pack with REF_DELTA' '
@@ -185,7 +190,11 @@ test_expect_success 'pack with REF_DELTA' '
190 '
191
192 test_expect_success 'unpack with REF_DELTA' '
188 - check_unpack test-2-${packname_2}
193 + check_unpack test-2-${packname_2} obj-list
194 +'
195 +
196 +test_expect_success 'unpack with REF_DELTA (core.fsyncmethod=batch)' '
197 + check_unpack test-2-${packname_2} obj-list "$BATCH_CONFIGURATION"
198 '
199
200 test_expect_success 'pack with OFS_DELTA' '
@@ -195,7 +204,11 @@ test_expect_success 'pack with OFS_DELTA' '
204 '
205
206 test_expect_success 'unpack with OFS_DELTA' '
198 - check_unpack test-3-${packname_3}
207 + check_unpack test-3-${packname_3} obj-list
208 +'
209 +
210 +test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
211 + check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
212 '
213
214 test_expect_success 'compare delta flavors' '