Skip to content

Commit 889c6f0

Browse files
j6tgitster
authored andcommitted
tests: use test_ln_s_add to remove SYMLINKS prerequisite (trivial cases)
There are many instances where the treatment of symbolic links in the object model and the algorithms are tested, but where it is not necessary to actually have a symbolic link in the worktree. Make adjustments to the tests and remove the SYMLINKS prerequisite when appropriate in trivial cases, where "trivial" means: - merely a replacement of 'ln -s a b && git add b' by test_ln_s_add is needed; - a test for symbolic link on the file system can be split off (and remains protected by SYMLINKS); - existing code is equivalent to test_ln_s_add. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ce415d commit 889c6f0

19 files changed

+106
-110
lines changed

t/t1004-read-tree-m-u-wf.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ test_expect_success '3-way not overwriting local changes (their side)' '
158158
159159
'
160160

161-
test_expect_success SYMLINKS 'funny symlink in work tree' '
161+
test_expect_success 'funny symlink in work tree' '
162162
163163
git reset --hard &&
164164
git checkout -b sym-b side-b &&
@@ -170,15 +170,14 @@ test_expect_success SYMLINKS 'funny symlink in work tree' '
170170
rm -fr a &&
171171
git checkout -b sym-a side-a &&
172172
mkdir -p a &&
173-
ln -s ../b a/b &&
174-
git add a/b &&
173+
test_ln_s_add ../b a/b &&
175174
git commit -m "we add a/b" &&
176175
177176
read_tree_u_must_succeed -m -u sym-a sym-a sym-b
178177
179178
'
180179

181-
test_expect_success SYMLINKS,SANITY 'funny symlink in work tree, un-unlink-able' '
180+
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
182181
183182
rm -fr a b &&
184183
git reset --hard &&

t/t2001-checkout-cache-clash.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ test_expect_success \
5959
'git read-tree -m $tree1 && git checkout-index -f -a'
6060
test_debug 'show_files $tree1'
6161

62-
test_expect_success SYMLINKS \
63-
'git update-index --add a symlink.' \
64-
'ln -s path0 path1 &&
65-
git update-index --add path1'
62+
test_expect_success \
63+
'add a symlink' \
64+
'test_ln_s_add path0 path1'
6665
test_expect_success \
6766
'writing tree out with git write-tree' \
6867
'tree3=$(git write-tree)'

t/t2004-checkout-cache-temp.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ test_expect_success \
194194
test $(cat ../$s1) = tree1asubdir/path5)
195195
)'
196196

197-
test_expect_success SYMLINKS \
197+
test_expect_success \
198198
'checkout --temp symlink' '
199199
rm -f path* .merge_* out .git/index &&
200-
ln -s b a &&
201-
git update-index --add a &&
200+
test_ln_s_add b a &&
202201
t4=$(git write-tree) &&
203202
rm -f .git/index &&
204203
git read-tree $t4 &&

t/t2007-checkout-symlink.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_description='git checkout to switch between branches with symlink<->dir'
66

77
. ./test-lib.sh
88

9-
test_expect_success SYMLINKS setup '
9+
test_expect_success setup '
1010
1111
mkdir frotz &&
1212
echo hello >frotz/filfre &&
@@ -25,25 +25,25 @@ test_expect_success SYMLINKS setup '
2525
2626
git rm --cached frotz/filfre &&
2727
mv frotz xyzzy &&
28-
ln -s xyzzy frotz &&
29-
git add xyzzy/filfre frotz &&
28+
test_ln_s_add xyzzy frotz &&
29+
git add xyzzy/filfre &&
3030
test_tick &&
3131
git commit -m "side moves frotz/ to xyzzy/ and adds frotz->xyzzy/"
3232
3333
'
3434

35-
test_expect_success SYMLINKS 'switch from symlink to dir' '
35+
test_expect_success 'switch from symlink to dir' '
3636
3737
git checkout master
3838
3939
'
4040

41-
test_expect_success SYMLINKS 'Remove temporary directories & switch to master' '
41+
test_expect_success 'Remove temporary directories & switch to master' '
4242
rm -fr frotz xyzzy nitfol &&
4343
git checkout -f master
4444
'
4545

46-
test_expect_success SYMLINKS 'switch from dir to symlink' '
46+
test_expect_success 'switch from dir to symlink' '
4747
4848
git checkout side
4949

t/t2021-checkout-overwrite.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,25 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' '
2929
test -f a/b
3030
'
3131

32-
test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink' '
32+
test_expect_success 'create a commit where dir a/b changed to symlink' '
3333
3434
rm -rf a/b && # cleanup if previous test failed
3535
git checkout -f -b symlink start &&
3636
rm -rf a/b &&
37-
ln -s foo a/b &&
3837
git add -A &&
38+
test_ln_s_add foo a/b &&
3939
git commit -m "dir to symlink"
4040
'
4141

42-
test_expect_success SYMLINKS 'checkout commit with dir must not remove untracked a/b' '
42+
test_expect_success 'checkout commit with dir must not remove untracked a/b' '
4343
4444
git rm --cached a/b &&
4545
git commit -m "un-track the symlink" &&
46-
test_must_fail git checkout start &&
46+
test_must_fail git checkout start
47+
'
48+
49+
test_expect_success SYMLINKS 'the symlink remained' '
50+
4751
test -h a/b
4852
'
4953

t/t2200-add-update.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ test_expect_success 'non-limited update in subdir leaves root alone' '
9696
test_cmp expect actual
9797
'
9898

99-
test_expect_success SYMLINKS 'replace a file with a symlink' '
99+
test_expect_success 'replace a file with a symlink' '
100100
101101
rm foo &&
102-
ln -s top foo &&
103-
git add -u -- foo
102+
test_ln_s_add top foo
104103
105104
'
106105

t/t3010-ls-files-killed-modified.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,15 @@ modified without reporting path9 and path10.
3939

4040
test_expect_success 'git update-index --add to add various paths.' '
4141
date >path0 &&
42-
if test_have_prereq SYMLINKS
43-
then
44-
ln -s xyzzy path1
45-
else
46-
date > path1
47-
fi &&
42+
test_ln_s_add xyzzy path1 &&
4843
mkdir path2 path3 &&
4944
date >path2/file2 &&
5045
date >path3/file3 &&
5146
: >path7 &&
5247
date >path8 &&
5348
: >path9 &&
5449
date >path10 &&
55-
git update-index --add -- path0 path1 path?/file? path7 path8 path9 path10 &&
50+
git update-index --add -- path0 path?/file? path7 path8 path9 path10 &&
5651
rm -fr path? # leave path10 alone
5752
'
5853

t/t3700-add.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ test_expect_success \
3030
*) echo fail; git ls-files --stage xfoo1; (exit 1);;
3131
esac'
3232

33-
test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by symlink' '
33+
test_expect_success 'git add: filemode=0 should not get confused by symlink' '
3434
rm -f xfoo1 &&
35-
ln -s foo xfoo1 &&
36-
git add xfoo1 &&
35+
test_ln_s_add foo xfoo1 &&
3736
case "`git ls-files --stage xfoo1`" in
3837
120000" "*xfoo1) echo pass;;
3938
*) echo fail; git ls-files --stage xfoo1; (exit 1);;
@@ -51,21 +50,19 @@ test_expect_success \
5150
*) echo fail; git ls-files --stage xfoo2; (exit 1);;
5251
esac'
5352

54-
test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by symlink' '
53+
test_expect_success 'git add: filemode=0 should not get confused by symlink' '
5554
rm -f xfoo2 &&
56-
ln -s foo xfoo2 &&
57-
git update-index --add xfoo2 &&
55+
test_ln_s_add foo xfoo2 &&
5856
case "`git ls-files --stage xfoo2`" in
5957
120000" "*xfoo2) echo pass;;
6058
*) echo fail; git ls-files --stage xfoo2; (exit 1);;
6159
esac
6260
'
6361

64-
test_expect_success SYMLINKS \
62+
test_expect_success \
6563
'git update-index --add: Test that executable bit is not used...' \
6664
'git config core.filemode 0 &&
67-
ln -s xfoo2 xfoo3 &&
68-
git update-index --add xfoo3 &&
65+
test_ln_s_add xfoo2 xfoo3 && # runs git update-index --add
6966
case "`git ls-files --stage xfoo3`" in
7067
120000" "*xfoo3) echo pass;;
7168
*) echo fail; git ls-files --stage xfoo3; (exit 1);;

t/t3903-stash.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,41 +336,58 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
336336

337337
# This test creates a commit with a symlink used for the following tests
338338

339-
test_expect_success SYMLINKS 'stash symlink to file' '
339+
test_expect_success 'stash symlink to file' '
340340
git reset --hard &&
341-
ln -s file filelink &&
342-
git add filelink &&
341+
test_ln_s_add file filelink &&
343342
git commit -m "Add symlink" &&
344343
rm filelink &&
345344
cp file filelink &&
346-
git stash save "symlink to file" &&
345+
git stash save "symlink to file"
346+
'
347+
348+
test_expect_success SYMLINKS 'this must have re-created the symlink' '
347349
test -h filelink &&
348-
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
350+
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
351+
'
352+
353+
test_expect_success 'unstash must re-create the file' '
349354
git stash apply &&
350355
! test -h filelink &&
351356
test bar = "$(cat file)"
352357
'
353358

354-
test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '
359+
test_expect_success 'stash symlink to file (stage rm)' '
355360
git reset --hard &&
356361
git rm filelink &&
357362
cp file filelink &&
358-
git stash save "symlink to file (stage rm)" &&
363+
git stash save "symlink to file (stage rm)"
364+
'
365+
366+
test_expect_success SYMLINKS 'this must have re-created the symlink' '
359367
test -h filelink &&
360-
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
368+
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
369+
'
370+
371+
test_expect_success 'unstash must re-create the file' '
361372
git stash apply &&
362373
! test -h filelink &&
363374
test bar = "$(cat file)"
364375
'
365376

366-
test_expect_success SYMLINKS 'stash symlink to file (full stage)' '
377+
test_expect_success 'stash symlink to file (full stage)' '
367378
git reset --hard &&
368379
rm filelink &&
369380
cp file filelink &&
370381
git add filelink &&
371-
git stash save "symlink to file (full stage)" &&
382+
git stash save "symlink to file (full stage)"
383+
'
384+
385+
test_expect_success SYMLINKS 'this must have re-created the symlink' '
372386
test -h filelink &&
373-
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
387+
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
388+
'
389+
390+
test_expect_success 'unstash must re-create the file' '
374391
git stash apply &&
375392
! test -h filelink &&
376393
test bar = "$(cat file)"

t/t4008-diff-break-rewrite.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ test_expect_success \
9999
'validate result of -B -M (#4)' \
100100
'compare_diff_raw expected current'
101101

102-
test_expect_success SYMLINKS \
102+
test_expect_success \
103103
'make file0 into something completely different' \
104104
'rm -f file0 &&
105-
ln -s frotz file0 &&
106-
git update-index file0 file1'
105+
test_ln_s_add frotz file0 &&
106+
git update-index file1'
107107

108108
test_expect_success \
109109
'run diff with -B' \
@@ -114,7 +114,7 @@ cat >expected <<\EOF
114114
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1
115115
EOF
116116

117-
test_expect_success SYMLINKS \
117+
test_expect_success \
118118
'validate result of -B (#5)' \
119119
'compare_diff_raw expected current'
120120

@@ -129,7 +129,7 @@ cat >expected <<\EOF
129129
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R file0 file1
130130
EOF
131131

132-
test_expect_success SYMLINKS \
132+
test_expect_success \
133133
'validate result of -B -M (#6)' \
134134
'compare_diff_raw expected current'
135135

@@ -144,7 +144,7 @@ cat >expected <<\EOF
144144
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1
145145
EOF
146146

147-
test_expect_success SYMLINKS \
147+
test_expect_success \
148148
'validate result of -M (#7)' \
149149
'compare_diff_raw expected current'
150150

0 commit comments

Comments
 (0)