Skip to content

Commit b6680f4

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 b6680f4

1 file changed

Lines changed: 40 additions & 70 deletions

File tree

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

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,27 @@ show_files() {
3535
sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
3636
}
3737

38-
date >path0
39-
mkdir path1
40-
date >path1/file1
41-
42-
test_expect_success \
43-
'git update-index --add various paths.' \
44-
'git update-index --add path0 path1/file1'
45-
46-
rm -fr path0 path1
47-
mkdir path0
48-
date >path0/file0
49-
date >path1
50-
51-
test_expect_success \
52-
'git checkout-index without -f should fail on conflicting work tree.' \
53-
'test_must_fail git checkout-index -a'
38+
test_expect_success 'git update-index --add various paths' '
39+
date >path0 &&
40+
mkdir path1 &&
41+
date >path1/file1 &&
42+
git update-index --add path0 path1/file1
43+
'
5444

55-
test_expect_success \
56-
'git checkout-index with -f should succeed.' \
57-
'git checkout-index -f -a'
45+
test_expect_success 'git checkout-index without -f should fail on conflicting work tree' '
46+
rm -fr path0 path1 &&
47+
mkdir path0 &&
48+
date >path0/file0 &&
49+
date >path1 &&
50+
test_must_fail git checkout-index -a
51+
'
5852

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

6360
test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
6461
mkdir -p tar/get &&
@@ -83,53 +80,26 @@ test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
8380
# path path3 is occupied by a non-directory. With "-f" it should remove
8481
# the symlink path3 and create directory path3 and file path3/file1.
8582

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'
83+
test_expect_success 'checkout-index -f resolves symlink conflict on leading path' '
84+
mkdir path2 &&
85+
date >path2/file0 &&
86+
git update-index --add path2/file0 &&
87+
tree1=$(git write-tree) &&
88+
mkdir path3 &&
89+
date >path3/file1 &&
90+
git update-index --add path3/file1 &&
91+
tree2=$(git write-tree) &&
92+
rm -fr path3 &&
93+
git read-tree -m $tree1 &&
94+
git checkout-index -f -a &&
95+
test_ln_s_add path2 path3 &&
96+
tree3=$(git write-tree) &&
97+
git read-tree $tree2 &&
98+
git checkout-index -f -a &&
99+
test_path_is_dir_not_symlink path2 &&
100+
test_path_is_dir_not_symlink path3 &&
101+
test_path_is_file_not_symlink path2/file0 &&
102+
test_path_is_file_not_symlink path3/file1
103+
'
134104

135105
test_done

0 commit comments

Comments
 (0)