Commit | Line | Data |
---|---|---|
b44ebb19 LH |
1 | #!/bin/sh |
2 | ||
3 | test_description='.git file | |
4 | ||
5 | Verify that plumbing commands work when .git is a file | |
6 | ' | |
7 | . ./test-lib.sh | |
8 | ||
9 | objpath() { | |
70eabce8 | 10 | echo "$1" | sed -e 's|\(..\)|\1/|' |
b44ebb19 LH |
11 | } |
12 | ||
b44ebb19 LH |
13 | test_expect_success 'initial setup' ' |
14 | REAL="$(pwd)/.real" && | |
15 | mv .git "$REAL" | |
16 | ' | |
17 | ||
18 | test_expect_success 'bad setup: invalid .git file format' ' | |
19 | echo "gitdir $REAL" >.git && | |
dedfdb9c | 20 | test_must_fail git rev-parse 2>.err && |
d4053966 | 21 | test_i18ngrep "invalid gitfile format" .err |
b44ebb19 LH |
22 | ' |
23 | ||
24 | test_expect_success 'bad setup: invalid .git file path' ' | |
25 | echo "gitdir: $REAL.not" >.git && | |
dedfdb9c | 26 | test_must_fail git rev-parse 2>.err && |
d4053966 | 27 | test_i18ngrep "not a git repository" .err |
b44ebb19 LH |
28 | ' |
29 | ||
30 | test_expect_success 'final setup + check rev-parse --git-dir' ' | |
31 | echo "gitdir: $REAL" >.git && | |
32 | test "$REAL" = "$(git rev-parse --git-dir)" | |
33 | ' | |
34 | ||
35 | test_expect_success 'check hash-object' ' | |
36 | echo "foo" >bar && | |
37 | SHA=$(cat bar | git hash-object -w --stdin) && | |
dedfdb9c | 38 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
39 | ' |
40 | ||
41 | test_expect_success 'check cat-file' ' | |
42 | git cat-file blob $SHA >actual && | |
2b14d072 | 43 | test_cmp bar actual |
b44ebb19 LH |
44 | ' |
45 | ||
46 | test_expect_success 'check update-index' ' | |
dedfdb9c | 47 | test_path_is_missing "$REAL/index" && |
b44ebb19 LH |
48 | rm -f "$REAL/objects/$(objpath $SHA)" && |
49 | git update-index --add bar && | |
dedfdb9c JK |
50 | test_path_is_file "$REAL/index" && |
51 | test_path_is_file "$REAL/objects/$(objpath $SHA)" | |
b44ebb19 LH |
52 | ' |
53 | ||
54 | test_expect_success 'check write-tree' ' | |
55 | SHA=$(git write-tree) && | |
dedfdb9c | 56 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
57 | ' |
58 | ||
59 | test_expect_success 'check commit-tree' ' | |
60 | SHA=$(echo "commit bar" | git commit-tree $SHA) && | |
dedfdb9c | 61 | test_path_is_file "$REAL/objects/$(objpath $SHA)" |
b44ebb19 LH |
62 | ' |
63 | ||
64 | test_expect_success 'check rev-list' ' | |
65 | echo $SHA >"$REAL/HEAD" && | |
66 | test "$SHA" = "$(git rev-list HEAD)" | |
67 | ' | |
68 | ||
86d26f24 | 69 | test_expect_success 'setup_git_dir twice in subdir' ' |
d95138e6 NTND |
70 | git init sgd && |
71 | ( | |
72 | cd sgd && | |
73 | git config alias.lsfi ls-files && | |
74 | mv .git .realgit && | |
75 | echo "gitdir: .realgit" >.git && | |
76 | mkdir subdir && | |
77 | cd subdir && | |
78 | >foo && | |
79 | git add foo && | |
80 | git lsfi >actual && | |
81 | echo foo >expected && | |
82 | test_cmp expected actual | |
83 | ) | |
84 | ' | |
85 | ||
31041209 NTND |
86 | test_expect_success 'enter_repo non-strict mode' ' |
87 | test_create_repo enter_repo && | |
88 | ( | |
89 | cd enter_repo && | |
90 | test_tick && | |
91 | test_commit foo && | |
92 | mv .git .realgit && | |
93 | echo "gitdir: .realgit" >.git | |
94 | ) && | |
0de267b2 | 95 | head=$(git -C enter_repo rev-parse HEAD) && |
31041209 | 96 | git ls-remote enter_repo >actual && |
0de267b2 | 97 | cat >expected <<-EOF && |
98 | $head HEAD | |
99 | $head refs/heads/master | |
100 | $head refs/tags/foo | |
31041209 NTND |
101 | EOF |
102 | test_cmp expected actual | |
103 | ' | |
104 | ||
0f64cc40 NTND |
105 | test_expect_success 'enter_repo linked checkout' ' |
106 | ( | |
107 | cd enter_repo && | |
108 | git worktree add ../foo refs/tags/foo | |
109 | ) && | |
0de267b2 | 110 | head=$(git -C enter_repo rev-parse HEAD) && |
0f64cc40 | 111 | git ls-remote foo >actual && |
0de267b2 | 112 | cat >expected <<-EOF && |
113 | $head HEAD | |
114 | $head refs/heads/master | |
115 | $head refs/tags/foo | |
0f64cc40 NTND |
116 | EOF |
117 | test_cmp expected actual | |
118 | ' | |
119 | ||
1f5fbe1f | 120 | test_expect_success 'enter_repo strict mode' ' |
0de267b2 | 121 | head=$(git -C enter_repo rev-parse HEAD) && |
1f5fbe1f | 122 | git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual && |
0de267b2 | 123 | cat >expected <<-EOF && |
124 | $head HEAD | |
125 | $head refs/heads/master | |
126 | $head refs/tags/foo | |
1f5fbe1f NTND |
127 | EOF |
128 | test_cmp expected actual | |
129 | ' | |
130 | ||
b44ebb19 | 131 | test_done |