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