t2000: modernise overall structure

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. * 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. Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Zakariyah Ali committed Mar 28, 2026 at 00:40 UTC d8e34f971b31ae6583e796626c7280732fca68e1
1 file changed +66 -56
t/t2000-conflict-when-checking-files-out.sh
+66 -56
@@ -35,30 +35,30 @@ show_files() {
35 sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
36 }
37
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
38 +test_expect_success 'prepare files path0 and path1/file1' '
39 + date >path0 &&
40 + mkdir path1 &&
41 + date >path1/file1 &&
42 + git update-index --add path0 path1/file1
43 +'
44
51 -test_expect_success \
52 - 'git checkout-index without -f should fail on conflicting work tree.' \
53 - 'test_must_fail git checkout-index -a'
45 +test_expect_success 'prepare working tree files with D/F conflicts' '
46 + rm -fr path0 path1 &&
47 + mkdir path0 &&
48 + date >path0/file0 &&
49 + date >path1
50 +'
51
55 -test_expect_success \
56 - 'git checkout-index with -f should succeed.' \
57 - 'git checkout-index -f -a'
52 +test_expect_success 'git checkout-index without -f should fail on conflicting work tree.' '
53 + test_must_fail git checkout-index -a
54 +'
55
59 -test_expect_success \
60 - 'git checkout-index conflicting paths.' \
61 - 'test -f path0 && test -d path1 && test -f path1/file1'
56 +test_expect_success 'git checkout-index with -f should succeed.' '
57 + git checkout-index -f -a &&
58 + test_path_is_file path0 &&
59 + test_path_is_dir path1 &&
60 + test_path_is_file path1/file1
61 +'
62
63 test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
64 mkdir -p tar/get &&
@@ -83,53 +83,63 @@ test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
83 # path path3 is occupied by a non-directory. With "-f" it should remove
84 # the symlink path3 and create directory path3 and file path3/file1.
85
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)'
86 +test_expect_success 'prepare path2/file0 and index' '
87 + mkdir path2 &&
88 + date >path2/file0 &&
89 + git update-index --add path2/file0
90 +'
91 +
92 +test_expect_success 'write tree with path2/file0' '
93 + tree1=$(git write-tree)
94 +'
95 +
96 test_debug 'show_files $tree1'
97
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)'
98 +test_expect_success 'prepare path3/file1 and index' '
99 + mkdir path3 &&
100 + date >path3/file1 &&
101 + git update-index --add path3/file1
102 +'
103 +
104 +test_expect_success 'write tree with path3/file1' '
105 + tree2=$(git write-tree)
106 +'
107 +
108 test_debug 'show_files $tree2'
109
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_expect_success 'read previously written tree and checkout.' '
111 + rm -fr path3 &&
112 + git read-tree -m $tree1 &&
113 + git checkout-index -f -a
114 +'
115 +
116 test_debug 'show_files $tree1'
117
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_expect_success 'add a symlink' '
119 + test_ln_s_add path2 path3
120 +'
121 +
122 +test_expect_success 'write tree with symlink path3' '
123 + tree3=$(git write-tree)
124 +'
125 +
126 test_debug 'show_files $tree3'
127
128 # Morten says "Got that?" here.
129 # Test begins.
130
123 -test_expect_success \
124 - 'read previously written tree and checkout.' \
125 - 'git read-tree $tree2 && git checkout-index -f -a'
131 +test_expect_success 'read previously written tree and checkout.' '
132 + git read-tree $tree2 &&
133 + git checkout-index -f -a
134 +'
135 +
136 test_debug 'show_files $tree2'
137
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'
138 +test_expect_success 'checking out conflicting path with -f' '
139 + test_path_is_dir_not_symlink path2 &&
140 + test_path_is_dir_not_symlink path3 &&
141 + test_path_is_file_not_symlink path2/file0 &&
142 + test_path_is_file_not_symlink path3/file1
143 +'
144
145 test_done