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 <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Sixt 2013-06-07 22:53:28 +02:00 committed by Junio C Hamano
parent 9ce415d972
commit 889c6f0e4d
19 changed files with 106 additions and 110 deletions

View File

@ -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 &&
@ -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 &&

View File

@ -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)'

View File

@ -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 &&

View File

@ -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 &&
@ -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

View File

@ -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
'

View File

@ -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
'

View File

@ -39,12 +39,7 @@ 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 &&
@ -52,7 +47,7 @@ test_expect_success 'git update-index --add to add various paths.' '
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
'

View File

@ -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);;
@ -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);;

View File

@ -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)"

View File

@ -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' \
@ -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'
@ -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'
@ -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'

View File

@ -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 &&

View File

@ -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 &&
@ -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 &&

View File

@ -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 &&
@ -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 &&
@ -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 &&

View File

@ -218,13 +218,13 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' '
rm -f dirty dirty2
test_expect_success SYMLINKS 'git mv should overwrite symlink to a file' '
test_expect_success 'git mv should overwrite symlink to a file' '
rm -fr .git &&
git init &&
echo 1 >moved &&
ln -s moved symlink &&
git add moved symlink &&
test_ln_s_add moved symlink &&
git add moved &&
test_must_fail git mv moved symlink &&
git mv -f moved symlink &&
! test -e moved &&
@ -237,22 +237,26 @@ test_expect_success SYMLINKS 'git mv should overwrite symlink to a file' '
rm -f moved symlink
test_expect_success SYMLINKS 'git mv should overwrite file with a symlink' '
test_expect_success 'git mv should overwrite file with a symlink' '
rm -fr .git &&
git init &&
echo 1 >moved &&
ln -s moved symlink &&
git add moved symlink &&
test_ln_s_add moved symlink &&
git add moved &&
test_must_fail git mv symlink moved &&
git mv -f symlink moved &&
! test -e symlink &&
test -h moved &&
git update-index --refresh &&
git diff-files --quiet
'
test_expect_success SYMLINKS 'check moved symlink' '
test -h moved
'
rm -f moved symlink
test_done

View File

@ -141,11 +141,10 @@ test_expect_success SYMLINKS 'will not overwrite untracked symlink in leading pa
test_path_is_missing .git/MERGE_HEAD
'
test_expect_success SYMLINKS 'will not be confused by symlink in leading path' '
test_expect_success 'will not be confused by symlink in leading path' '
git reset --hard c0 &&
rm -rf sub &&
ln -s sub2 sub &&
git add sub &&
test_ln_s_add sub2 sub &&
git commit -m ln &&
git checkout sub
'

View File

@ -18,17 +18,13 @@ test_expect_success 'setup ' '
echo "bin: test number 0" >zero.bin &&
echo "bin: test 1" >one.bin &&
echo "bin: test number 2" >two.bin &&
if test_have_prereq SYMLINKS; then
ln -s one.bin symlink.bin
fi &&
test_ln_s_add one.bin symlink.bin &&
git add . &&
GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
echo "bin: test 1 version 2" >one.bin &&
echo "bin: test number 2 version 2" >>two.bin &&
if test_have_prereq SYMLINKS; then
rm symlink.bin &&
ln -s two.bin symlink.bin
fi &&
rm -f symlink.bin &&
test_ln_s_add two.bin symlink.bin &&
GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
'
@ -135,7 +131,7 @@ test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
# cp two.bin three.bin and make small tweak
# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
test_expect_success SYMLINKS 'make another new commit' '
test_expect_success 'make another new commit' '
cat >three.bin <<\EOF &&
bin: test number 2
bin: test number 2 version 2
@ -146,7 +142,7 @@ EOF
GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
'
test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
test_expect_success 'blame on last commit (-C -C, symlink)' '
git blame -C -C three.bin >blame &&
find_blame <blame >result &&
cat >expected <<\EOF &&

View File

@ -12,9 +12,7 @@ chmod +x helper
test_expect_success 'setup ' '
echo "bin: test" >one.bin &&
if test_have_prereq SYMLINKS; then
ln -s one.bin symlink.bin
fi &&
test_ln_s_add one.bin symlink.bin &&
git add . &&
GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
echo "bin: test version 2" >one.bin &&
@ -72,14 +70,14 @@ test_expect_success 'cat-file --textconv on previous commit' '
test_cmp expected result
'
test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
test_expect_success 'cat-file without --textconv (symlink)' '
git cat-file blob :symlink.bin >result &&
printf "%s" "one.bin" >expected
test_cmp expected result
'
test_expect_success SYMLINKS 'cat-file --textconv on index (symlink)' '
test_expect_success 'cat-file --textconv on index (symlink)' '
! git cat-file --textconv :symlink.bin 2>result &&
cat >expected <<\EOF &&
fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
@ -87,7 +85,7 @@ EOF
test_cmp expected result
'
test_expect_success SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
test_expect_success 'cat-file --textconv on HEAD (symlink)' '
! git cat-file --textconv HEAD:symlink.bin 2>result &&
cat >expected <<EOF &&
fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin

View File

@ -396,7 +396,7 @@ test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
test_expect_success SYMLINKS 'directory becomes symlink' '
test_expect_success 'directory becomes symlink' '
git init dirtosymlink &&
git init result &&
(
@ -408,8 +408,7 @@ test_expect_success SYMLINKS 'directory becomes symlink' '
git add foo/world bar/world &&
git commit -q -mone &&
git rm -r foo &&
ln -s bar foo &&
git add foo &&
test_ln_s_add bar foo &&
git commit -q -mtwo
) &&
(

View File

@ -156,10 +156,10 @@ test_expect_success \
git commit -a -m "File renamed." &&
gitweb_run "p=.git;a=commitdiff"'
test_expect_success SYMLINKS \
test_expect_success \
'commitdiff(0): file to symlink' \
'rm renamed_file &&
ln -s file renamed_file &&
test_ln_s_add file renamed_file &&
git commit -a -m "File to symlink." &&
gitweb_run "p=.git;a=commitdiff"'
@ -212,15 +212,14 @@ test_expect_success \
# ----------------------------------------------------------------------
# commitdiff testing (taken from t4114-apply-typechange.sh)
test_expect_success SYMLINKS 'setup typechange commits' '
test_expect_success 'setup typechange commits' '
echo "hello world" > foo &&
echo "hi planet" > bar &&
git update-index --add foo bar &&
git commit -m initial &&
git branch initial &&
rm -f foo &&
ln -s bar foo &&
git update-index foo &&
test_ln_s_add bar foo &&
git commit -m "foo symlinked to bar" &&
git branch foo-symlinked-to-bar &&
rm -f foo &&
@ -361,11 +360,7 @@ test_expect_success \
echo "Changed" >> 04-rename-to &&
test_chmod +x 05-mode-change &&
rm -f 06-file-or-symlink &&
if test_have_prereq SYMLINKS; then
ln -s 01-change 06-file-or-symlink
else
printf %s 01-change > 06-file-or-symlink
fi &&
test_ln_s_add 01-change 06-file-or-symlink &&
echo "Changed and have mode changed" > 07-change-mode-change &&
test_chmod +x 07-change-mode-change &&
git commit -a -m "Large commit" &&