1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 14:57:52 +01:00
git/t/t5522-pull-symlink.sh
Johannes Sixt 704a3143d5 Use prerequisite tags to skip tests that depend on symbolic links
Many tests depend on that symbolic links work.  This introduces a check
that sets the prerequisite tag SYMLINKS if the file system supports
symbolic links.  Since so many tests have to check for this prerequisite,
we do the check in test-lib.sh, so that we don't need to repeat the test
in many scripts.

To check for 'ln -s' failures, you can use a FAT partition on Linux:

$ mkdosfs -C git-on-fat 1000000
$ sudo mount -o loop,uid=j6t,gid=users,shortname=winnt git-on-fat /mnt

Clone git to /mnt and

$ GIT_SKIP_TESTS='t0001.1[34] t0010 t1301 t403[34] t4129.[47] t5701.7
          t7701.3 t9100 t9101.26 t9119 t9124.[67] t9200.10 t9600.6' \
        make test

(These additionally skipped tests depend on POSIX permissions that FAT on
Linux does not provide.)

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2009-03-22 17:26:44 +01:00

85 lines
2 KiB
Bash
Executable file

#!/bin/sh
test_description='pulling from symlinked subdir'
. ./test-lib.sh
if ! test_have_prereq SYMLINKS
then
say 'Symbolic links not supported, skipping tests.'
test_done
exit
fi
# The scenario we are building:
#
# trash\ directory/
# clone-repo/
# subdir/
# bar
# subdir-link -> clone-repo/subdir/
#
# The working directory is subdir-link.
mkdir subdir
echo file >subdir/file
git add subdir/file
git commit -q -m file
git clone -q . clone-repo
ln -s clone-repo/subdir/ subdir-link
# Demonstrate that things work if we just avoid the symlink
#
test_expect_success 'pulling from real subdir' '
(
echo real >subdir/file &&
git commit -m real subdir/file &&
cd clone-repo/subdir/ &&
git pull &&
test real = $(cat file)
)
'
# From subdir-link, pulling should work as it does from
# clone-repo/subdir/.
#
# Instead, the error pull gave was:
#
# fatal: 'origin': unable to chdir or not a git archive
# fatal: The remote end hung up unexpectedly
#
# because git would find the .git/config for the "trash directory"
# repo, not for the clone-repo repo. The "trash directory" repo
# had no entry for origin. Git found the wrong .git because
# git rev-parse --show-cdup printed a path relative to
# clone-repo/subdir/, not subdir-link/. Git rev-parse --show-cdup
# used the correct .git, but when the git pull shell script did
# "cd `git rev-parse --show-cdup`", it ended up in the wrong
# directory. A POSIX shell's "cd" works a little differently
# than chdir() in C; "cd -P" is much closer to chdir().
#
test_expect_success 'pulling from symlinked subdir' '
(
echo link >subdir/file &&
git commit -m link subdir/file &&
cd subdir-link/ &&
git pull &&
test link = $(cat file)
)
'
# Prove that the remote end really is a repo, and other commands
# work fine in this context. It's just that "git pull" breaks.
#
test_expect_success 'pushing from symlinked subdir' '
(
cd subdir-link/ &&
echo push >file &&
git commit -m push ./file &&
git push
) &&
test push = $(git show HEAD:subdir/file)
'
test_done