Skip to content

Commit

Permalink
tests: use test_ln_s_add to remove SYMLINKS prerequisite (trivial cases)
Browse files Browse the repository at this point in the history
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 <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Jun 7, 2013
1 parent 9ce415d commit 889c6f0
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 110 deletions.
7 changes: 3 additions & 4 deletions t/t1004-read-tree-m-u-wf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_expect_success '3-way not overwriting local changes (their side)' '
'

test_expect_success SYMLINKS 'funny symlink in work tree' '
test_expect_success 'funny symlink in work tree' '
git reset --hard &&
git checkout -b sym-b side-b &&
Expand All @@ -170,15 +170,14 @@ test_expect_success SYMLINKS 'funny symlink in work tree' '
rm -fr a &&
git checkout -b sym-a side-a &&
mkdir -p a &&
ln -s ../b a/b &&
git add a/b &&
test_ln_s_add ../b a/b &&
git commit -m "we add a/b" &&
read_tree_u_must_succeed -m -u sym-a sym-a sym-b
'

test_expect_success SYMLINKS,SANITY 'funny symlink in work tree, un-unlink-able' '
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
rm -fr a b &&
git reset --hard &&
Expand Down
7 changes: 3 additions & 4 deletions t/t2001-checkout-cache-clash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ test_expect_success \
'git read-tree -m $tree1 && git checkout-index -f -a'
test_debug 'show_files $tree1'

test_expect_success SYMLINKS \
'git update-index --add a symlink.' \
'ln -s path0 path1 &&
git update-index --add path1'
test_expect_success \
'add a symlink' \
'test_ln_s_add path0 path1'
test_expect_success \
'writing tree out with git write-tree' \
'tree3=$(git write-tree)'
Expand Down
5 changes: 2 additions & 3 deletions t/t2004-checkout-cache-temp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ test_expect_success \
test $(cat ../$s1) = tree1asubdir/path5)
)'

test_expect_success SYMLINKS \
test_expect_success \
'checkout --temp symlink' '
rm -f path* .merge_* out .git/index &&
ln -s b a &&
git update-index --add a &&
test_ln_s_add b a &&
t4=$(git write-tree) &&
rm -f .git/index &&
git read-tree $t4 &&
Expand Down
12 changes: 6 additions & 6 deletions t/t2007-checkout-symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_description='git checkout to switch between branches with symlink<->dir'

. ./test-lib.sh

test_expect_success SYMLINKS setup '
test_expect_success setup '
mkdir frotz &&
echo hello >frotz/filfre &&
Expand All @@ -25,25 +25,25 @@ test_expect_success SYMLINKS setup '
git rm --cached frotz/filfre &&
mv frotz xyzzy &&
ln -s xyzzy frotz &&
git add xyzzy/filfre frotz &&
test_ln_s_add xyzzy frotz &&
git add xyzzy/filfre &&
test_tick &&
git commit -m "side moves frotz/ to xyzzy/ and adds frotz->xyzzy/"
'

test_expect_success SYMLINKS 'switch from symlink to dir' '
test_expect_success 'switch from symlink to dir' '
git checkout master
'

test_expect_success SYMLINKS 'Remove temporary directories & switch to master' '
test_expect_success 'Remove temporary directories & switch to master' '
rm -fr frotz xyzzy nitfol &&
git checkout -f master
'

test_expect_success SYMLINKS 'switch from dir to symlink' '
test_expect_success 'switch from dir to symlink' '
git checkout side
Expand Down
12 changes: 8 additions & 4 deletions t/t2021-checkout-overwrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' '
test -f a/b
'

test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink' '
test_expect_success 'create a commit where dir a/b changed to symlink' '
rm -rf a/b && # cleanup if previous test failed
git checkout -f -b symlink start &&
rm -rf a/b &&
ln -s foo a/b &&
git add -A &&
test_ln_s_add foo a/b &&
git commit -m "dir to symlink"
'

test_expect_success SYMLINKS 'checkout commit with dir must not remove untracked a/b' '
test_expect_success 'checkout commit with dir must not remove untracked a/b' '
git rm --cached a/b &&
git commit -m "un-track the symlink" &&
test_must_fail git checkout start &&
test_must_fail git checkout start
'

test_expect_success SYMLINKS 'the symlink remained' '
test -h a/b
'

Expand Down
5 changes: 2 additions & 3 deletions t/t2200-add-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ test_expect_success 'non-limited update in subdir leaves root alone' '
test_cmp expect actual
'

test_expect_success SYMLINKS 'replace a file with a symlink' '
test_expect_success 'replace a file with a symlink' '
rm foo &&
ln -s top foo &&
git add -u -- foo
test_ln_s_add top foo
'

Expand Down
9 changes: 2 additions & 7 deletions t/t3010-ls-files-killed-modified.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,15 @@ modified without reporting path9 and path10.

test_expect_success 'git update-index --add to add various paths.' '
date >path0 &&
if test_have_prereq SYMLINKS
then
ln -s xyzzy path1
else
date > path1
fi &&
test_ln_s_add xyzzy path1 &&
mkdir path2 path3 &&
date >path2/file2 &&
date >path3/file3 &&
: >path7 &&
date >path8 &&
: >path9 &&
date >path10 &&
git update-index --add -- path0 path1 path?/file? path7 path8 path9 path10 &&
git update-index --add -- path0 path?/file? path7 path8 path9 path10 &&
rm -fr path? # leave path10 alone
'

Expand Down
15 changes: 6 additions & 9 deletions t/t3700-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ test_expect_success \
*) echo fail; git ls-files --stage xfoo1; (exit 1);;
esac'

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

test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by symlink' '
test_expect_success 'git add: filemode=0 should not get confused by symlink' '
rm -f xfoo2 &&
ln -s foo xfoo2 &&
git update-index --add xfoo2 &&
test_ln_s_add foo xfoo2 &&
case "`git ls-files --stage xfoo2`" in
120000" "*xfoo2) echo pass;;
*) echo fail; git ls-files --stage xfoo2; (exit 1);;
esac
'

test_expect_success SYMLINKS \
test_expect_success \
'git update-index --add: Test that executable bit is not used...' \
'git config core.filemode 0 &&
ln -s xfoo2 xfoo3 &&
git update-index --add xfoo3 &&
test_ln_s_add xfoo2 xfoo3 && # runs git update-index --add
case "`git ls-files --stage xfoo3`" in
120000" "*xfoo3) echo pass;;
*) echo fail; git ls-files --stage xfoo3; (exit 1);;
Expand Down
39 changes: 28 additions & 11 deletions t/t3903-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,41 +336,58 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '

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

test_expect_success SYMLINKS 'stash symlink to file' '
test_expect_success 'stash symlink to file' '
git reset --hard &&
ln -s file filelink &&
git add filelink &&
test_ln_s_add file filelink &&
git commit -m "Add symlink" &&
rm filelink &&
cp file filelink &&
git stash save "symlink to file" &&
git stash save "symlink to file"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
test -h filelink &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
git stash apply &&
! test -h filelink &&
test bar = "$(cat file)"
'

test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '
test_expect_success 'stash symlink to file (stage rm)' '
git reset --hard &&
git rm filelink &&
cp file filelink &&
git stash save "symlink to file (stage rm)" &&
git stash save "symlink to file (stage rm)"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
test -h filelink &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
git stash apply &&
! test -h filelink &&
test bar = "$(cat file)"
'

test_expect_success SYMLINKS 'stash symlink to file (full stage)' '
test_expect_success 'stash symlink to file (full stage)' '
git reset --hard &&
rm filelink &&
cp file filelink &&
git add filelink &&
git stash save "symlink to file (full stage)" &&
git stash save "symlink to file (full stage)"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
test -h filelink &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
git stash apply &&
! test -h filelink &&
test bar = "$(cat file)"
Expand Down
12 changes: 6 additions & 6 deletions t/t4008-diff-break-rewrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ test_expect_success \
'validate result of -B -M (#4)' \
'compare_diff_raw expected current'

test_expect_success SYMLINKS \
test_expect_success \
'make file0 into something completely different' \
'rm -f file0 &&
ln -s frotz file0 &&
git update-index file0 file1'
test_ln_s_add frotz file0 &&
git update-index file1'

test_expect_success \
'run diff with -B' \
Expand All @@ -114,7 +114,7 @@ cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1
EOF

test_expect_success SYMLINKS \
test_expect_success \
'validate result of -B (#5)' \
'compare_diff_raw expected current'

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

test_expect_success SYMLINKS \
test_expect_success \
'validate result of -B -M (#6)' \
'compare_diff_raw expected current'

Expand All @@ -144,7 +144,7 @@ cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1
EOF

test_expect_success SYMLINKS \
test_expect_success \
'validate result of -M (#7)' \
'compare_diff_raw expected current'

Expand Down
8 changes: 3 additions & 5 deletions t/t4030-diff-textconv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ index 0000000..67be421
+frotz
\ No newline at end of file
EOF
# make a symlink the hard way that works on symlink-challenged file systems

test_expect_success 'textconv does not act on symlinks' '
printf frotz > file &&
git add file &&
git ls-files -s | sed -e s/100644/120000/ |
git update-index --index-info &&
rm -f file &&
test_ln_s_add frotz file &&
git commit -m typechange &&
git show >diff &&
find_diff <diff >actual &&
Expand Down
10 changes: 4 additions & 6 deletions t/t4115-apply-symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ test_description='git apply symlinks and partial files

. ./test-lib.sh

test_expect_success SYMLINKS setup '
test_expect_success setup '
ln -s path1/path2/path3/path4/path5 link1 &&
git add link? &&
test_ln_s_add path1/path2/path3/path4/path5 link1 &&
git commit -m initial &&
git branch side &&
rm -f link? &&
ln -s htap6 link1 &&
git update-index link? &&
test_ln_s_add htap6 link1 &&
git commit -m second &&
git diff-tree -p HEAD^ HEAD >patch &&
Expand All @@ -37,7 +35,7 @@ test_expect_success SYMLINKS 'apply symlink patch' '
'

test_expect_success SYMLINKS 'apply --index symlink patch' '
test_expect_success 'apply --index symlink patch' '
git checkout -f side &&
git apply --index patch &&
Expand Down
8 changes: 4 additions & 4 deletions t/t4122-apply-symlink-inside.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ lecho () {
done
}

test_expect_success SYMLINKS setup '
test_expect_success setup '
mkdir -p arch/i386/boot arch/x86_64 &&
lecho 1 2 3 4 5 >arch/i386/boot/Makefile &&
ln -s ../i386/boot arch/x86_64/boot &&
test_ln_s_add ../i386/boot arch/x86_64/boot &&
git add . &&
test_tick &&
git commit -m initial &&
Expand All @@ -31,7 +31,7 @@ test_expect_success SYMLINKS setup '
'

test_expect_success SYMLINKS apply '
test_expect_success apply '
git checkout test &&
git diff --exit-code test &&
Expand All @@ -40,7 +40,7 @@ test_expect_success SYMLINKS apply '
'

test_expect_success SYMLINKS 'check result' '
test_expect_success 'check result' '
git diff --exit-code master &&
git diff --exit-code --cached master &&
Expand Down
Loading

0 comments on commit 889c6f0

Please sign in to comment.