]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5522-pull-symlink.sh
grep -O: Do not pass color sequences as filenames to pager
[thirdparty/git.git] / t / t5522-pull-symlink.sh
1 #!/bin/sh
2
3 test_description='pulling from symlinked subdir'
4
5 . ./test-lib.sh
6
7 if ! test_have_prereq SYMLINKS
8 then
9 say 'Symbolic links not supported, skipping tests.'
10 test_done
11 fi
12
13 # The scenario we are building:
14 #
15 # trash\ directory/
16 # clone-repo/
17 # subdir/
18 # bar
19 # subdir-link -> clone-repo/subdir/
20 #
21 # The working directory is subdir-link.
22
23 test_expect_success setup '
24 mkdir subdir &&
25 echo file >subdir/file &&
26 git add subdir/file &&
27 git commit -q -m file &&
28 git clone -q . clone-repo &&
29 ln -s clone-repo/subdir/ subdir-link &&
30 (
31 cd clone-repo &&
32 git config receive.denyCurrentBranch warn
33 ) &&
34 git config receive.denyCurrentBranch warn
35 '
36
37 # Demonstrate that things work if we just avoid the symlink
38 #
39 test_expect_success 'pulling from real subdir' '
40 (
41 echo real >subdir/file &&
42 git commit -m real subdir/file &&
43 cd clone-repo/subdir/ &&
44 git pull &&
45 test real = $(cat file)
46 )
47 '
48
49 # From subdir-link, pulling should work as it does from
50 # clone-repo/subdir/.
51 #
52 # Instead, the error pull gave was:
53 #
54 # fatal: 'origin': unable to chdir or not a git archive
55 # fatal: The remote end hung up unexpectedly
56 #
57 # because git would find the .git/config for the "trash directory"
58 # repo, not for the clone-repo repo. The "trash directory" repo
59 # had no entry for origin. Git found the wrong .git because
60 # git rev-parse --show-cdup printed a path relative to
61 # clone-repo/subdir/, not subdir-link/. Git rev-parse --show-cdup
62 # used the correct .git, but when the git pull shell script did
63 # "cd `git rev-parse --show-cdup`", it ended up in the wrong
64 # directory. A POSIX shell's "cd" works a little differently
65 # than chdir() in C; "cd -P" is much closer to chdir().
66 #
67 test_expect_success 'pulling from symlinked subdir' '
68 (
69 echo link >subdir/file &&
70 git commit -m link subdir/file &&
71 cd subdir-link/ &&
72 git pull &&
73 test link = $(cat file)
74 )
75 '
76
77 # Prove that the remote end really is a repo, and other commands
78 # work fine in this context. It's just that "git pull" breaks.
79 #
80 test_expect_success 'pushing from symlinked subdir' '
81 (
82 cd subdir-link/ &&
83 echo push >file &&
84 git commit -m push ./file &&
85 git push
86 ) &&
87 test push = $(git show HEAD:subdir/file)
88 '
89
90 test_done