Skip to content

Commit e4cab72

Browse files
neerajsi-msftdscho
authored andcommitted
core.fsyncobjectfiles: 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc34e7b commit e4cab72

File tree

4 files changed

+89
-11
lines changed

4 files changed

+89
-11
lines changed

t/lib-unique-files.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Helper to create files with unique contents
2+
3+
4+
# Create multiple files with unique contents. Takes the number of
5+
# directories, the number of files in each directory, and the base
6+
# directory.
7+
#
8+
# test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files
9+
# each in my_dir, all with unique
10+
# contents.
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+
test_tick
20+
local basedata=$test_tick
21+
22+
23+
rm -rf $basedir
24+
25+
for i in $(test_seq $dirs)
26+
do
27+
local dir=$basedir/dir$i
28+
29+
mkdir -p "$dir"
30+
for j in $(test_seq $files)
31+
do
32+
counter=$((counter + 1))
33+
echo "$basedata.$counter" >"$dir/file$j.txt"
34+
done
35+
done
36+
}

t/t3700-add.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ test_description='Test of git add, including the -- option.'
88
TEST_PASSES_SANITIZE_LEAK=true
99
. ./test-lib.sh
1010

11+
. $TEST_DIRECTORY/lib-unique-files.sh
12+
1113
# Test the file mode "$1" of the file "$2" in the index.
1214
test_mode_in_index () {
1315
case "$(git ls-files -s "$2")" in
@@ -34,6 +36,24 @@ test_expect_success \
3436
'Test that "git add -- -q" works' \
3537
'touch -- -q && git add -- -q'
3638

39+
test_expect_success 'git add: core.fsyncobjectfiles=batch' "
40+
test_create_unique_files 2 4 fsync-files &&
41+
git -c core.fsyncobjectfiles=batch add -- ./fsync-files/ &&
42+
rm -f fsynced_files &&
43+
git ls-files --stage fsync-files/ > fsynced_files &&
44+
test_line_count = 8 fsynced_files &&
45+
awk -- '{print \$2}' fsynced_files | xargs -n1 git cat-file -e
46+
"
47+
48+
test_expect_success 'git update-index: core.fsyncobjectfiles=batch' "
49+
test_create_unique_files 2 4 fsync-files2 &&
50+
find fsync-files2 ! -type d -print | xargs git -c core.fsyncobjectfiles=batch update-index --add -- &&
51+
rm -f fsynced_files2 &&
52+
git ls-files --stage fsync-files2/ > fsynced_files2 &&
53+
test_line_count = 8 fsynced_files2 &&
54+
awk -- '{print \$2}' fsynced_files2 | xargs -n1 git cat-file -e
55+
"
56+
3757
test_expect_success \
3858
'git add: Test that executable bit is not used if core.filemode=0' \
3959
'git config core.filemode 0 &&

t/t3903-stash.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

1111
. ./test-lib.sh
12+
. $TEST_DIRECTORY/lib-unique-files.sh
1213

1314
test_expect_success 'usage on cmd and subcommand invalid option' '
1415
test_expect_code 129 git stash --invalid-option 2>usage &&
@@ -1323,6 +1324,19 @@ test_expect_success 'stash handles skip-worktree entries nicely' '
13231324
git rev-parse --verify refs/stash:A.t
13241325
'
13251326

1327+
test_expect_success 'stash with core.fsyncobjectfiles=batch' "
1328+
test_create_unique_files 2 4 fsync-files &&
1329+
git -c core.fsyncobjectfiles=batch stash push -u -- ./fsync-files/ &&
1330+
rm -f fsynced_files &&
1331+
1332+
# The files were untracked, so use the third parent,
1333+
# which contains the untracked files
1334+
git ls-tree -r stash^3 -- ./fsync-files/ > fsynced_files &&
1335+
test_line_count = 8 fsynced_files &&
1336+
awk -- '{print \$3}' fsynced_files | xargs -n1 git cat-file -e
1337+
"
1338+
1339+
13261340
test_expect_success 'stash -c stash.useBuiltin=false warning ' '
13271341
expected="stash.useBuiltin support has been removed" &&
13281342

t/t5300-pack-object.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,23 @@ test_expect_success 'pack-objects with bogus arguments' '
162162

163163
check_unpack () {
164164
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
165+
git $2 init --bare git2 &&
166+
(
167+
git $2 -C git2 unpack-objects -n <"$1".pack &&
168+
git $2 -C git2 unpack-objects <"$1".pack &&
169+
git $2 -C git2 cat-file --batch-check="%(objectname)"
170+
) <obj-list >current &&
171+
cmp obj-list current
176172
}
177173

178174
test_expect_success 'unpack without delta' '
179175
check_unpack test-1-${packname_1}
180176
'
181177

178+
test_expect_success 'unpack without delta (core.fsyncobjectfiles=batch)' '
179+
check_unpack test-1-${packname_1} "-c core.fsyncobjectfiles=batch"
180+
'
181+
182182
test_expect_success 'pack with REF_DELTA' '
183183
packname_2=$(git pack-objects --progress test-2 <obj-list 2>stderr) &&
184184
check_deltas stderr -gt 0
@@ -188,6 +188,10 @@ test_expect_success 'unpack with REF_DELTA' '
188188
check_unpack test-2-${packname_2}
189189
'
190190

191+
test_expect_success 'unpack with REF_DELTA (core.fsyncobjectfiles=batch)' '
192+
check_unpack test-2-${packname_2} "-c core.fsyncobjectfiles=batch"
193+
'
194+
191195
test_expect_success 'pack with OFS_DELTA' '
192196
packname_3=$(git pack-objects --progress --delta-base-offset test-3 \
193197
<obj-list 2>stderr) &&
@@ -198,6 +202,10 @@ test_expect_success 'unpack with OFS_DELTA' '
198202
check_unpack test-3-${packname_3}
199203
'
200204

205+
test_expect_success 'unpack with OFS_DELTA (core.fsyncobjectfiles=batch)' '
206+
check_unpack test-3-${packname_3} "-c core.fsyncobjectfiles=batch"
207+
'
208+
201209
test_expect_success 'compare delta flavors' '
202210
perl -e '\''
203211
defined($_ = -s $_) or die for @ARGV;

0 commit comments

Comments
 (0)