Skip to content

Commit de6fb2c

Browse files
committed
t2000: modernize overall structure and path checks
This test script that dates back to 2005 certainly shows its age and both its style and the way the tests are laid out do not match the modern standard. Modernize it to match the current testing standards: * Executables that prepare the data used to test the command should be inside the test_expect_success block in modern tests. * In modern tests, running a command that is being tested, making sure it succeeds, and inspecting other side effects that are expected, are all done in a single test_expect_success block. * A test_expect_success block in modern tests are laid out as test_expect_success 'title of the test' ' body of the test && ... body of the test ' not as test_expect_success \ 'title of the test' \ 'body of the test && ... body of the test' which is in a prehistoric style. * In modern tests, each &&-chained statement in the body of the test_expect_success block are indented with a horizontal tab, unlike prehistoric style that used 4-space indent. * Replace bare 'test -f/-d' and 'test ! -h' assertions with dedicated test_path_is_* helpers (specifically test_path_is_file_not_symlink and test_path_is_dir_not_symlink). While less commonly used in the test suite than test_path_is_file/dir, they act as direct replacements for the specific checks being performed and provide clearer diagnostics on failure. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com>
1 parent 41688c1 commit de6fb2c

1 file changed

Lines changed: 30 additions & 58 deletions

File tree

t/t2000-conflict-when-checking-files-out.sh

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ mkdir path0
4848
date >path0/file0
4949
date >path1
5050

51-
test_expect_success \
52-
'git checkout-index without -f should fail on conflicting work tree.' \
53-
'test_must_fail git checkout-index -a'
54-
55-
test_expect_success \
56-
'git checkout-index with -f should succeed.' \
57-
'git checkout-index -f -a'
51+
test_expect_success 'git checkout-index without -f should fail on conflicting work tree.' '
52+
test_must_fail git checkout-index -a
53+
'
5854

59-
test_expect_success \
60-
'git checkout-index conflicting paths.' \
61-
'test -f path0 && test -d path1 && test -f path1/file1'
55+
test_expect_success 'git checkout-index with -f should succeed.' '
56+
git checkout-index -f -a &&
57+
test_path_is_file path0 &&
58+
test_path_is_dir path1 &&
59+
test_path_is_file path1/file1
60+
'
6261

6362
test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
6463
mkdir -p tar/get &&
@@ -83,53 +82,26 @@ test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
8382
# path path3 is occupied by a non-directory. With "-f" it should remove
8483
# the symlink path3 and create directory path3 and file path3/file1.
8584

86-
mkdir path2
87-
date >path2/file0
88-
test_expect_success \
89-
'git update-index --add path2/file0' \
90-
'git update-index --add path2/file0'
91-
test_expect_success \
92-
'writing tree out with git write-tree' \
93-
'tree1=$(git write-tree)'
94-
test_debug 'show_files $tree1'
95-
96-
mkdir path3
97-
date >path3/file1
98-
test_expect_success \
99-
'git update-index --add path3/file1' \
100-
'git update-index --add path3/file1'
101-
test_expect_success \
102-
'writing tree out with git write-tree' \
103-
'tree2=$(git write-tree)'
104-
test_debug 'show_files $tree2'
105-
106-
rm -fr path3
107-
test_expect_success \
108-
'read previously written tree and checkout.' \
109-
'git read-tree -m $tree1 && git checkout-index -f -a'
110-
test_debug 'show_files $tree1'
111-
112-
test_expect_success \
113-
'add a symlink' \
114-
'test_ln_s_add path2 path3'
115-
test_expect_success \
116-
'writing tree out with git write-tree' \
117-
'tree3=$(git write-tree)'
118-
test_debug 'show_files $tree3'
119-
120-
# Morten says "Got that?" here.
121-
# Test begins.
122-
123-
test_expect_success \
124-
'read previously written tree and checkout.' \
125-
'git read-tree $tree2 && git checkout-index -f -a'
126-
test_debug 'show_files $tree2'
127-
128-
test_expect_success \
129-
'checking out conflicting path with -f' \
130-
'test ! -h path2 && test -d path2 &&
131-
test ! -h path3 && test -d path3 &&
132-
test ! -h path2/file0 && test -f path2/file0 &&
133-
test ! -h path3/file1 && test -f path3/file1'
85+
test_expect_success 'checkout-index -f resolves symlink conflict on leading path' '
86+
mkdir path2 &&
87+
date >path2/file0 &&
88+
git update-index --add path2/file0 &&
89+
tree1=$(git write-tree) &&
90+
mkdir path3 &&
91+
date >path3/file1 &&
92+
git update-index --add path3/file1 &&
93+
tree2=$(git write-tree) &&
94+
rm -fr path3 &&
95+
git read-tree -m $tree1 &&
96+
git checkout-index -f -a &&
97+
test_ln_s_add path2 path3 &&
98+
tree3=$(git write-tree) &&
99+
git read-tree $tree2 &&
100+
git checkout-index -f -a &&
101+
test_path_is_dir_not_symlink path2 &&
102+
test_path_is_dir_not_symlink path3 &&
103+
test_path_is_file_not_symlink path2/file0 &&
104+
test_path_is_file_not_symlink path3/file1
105+
'
134106

135107
test_done

0 commit comments

Comments
 (0)