interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5547-push-quarantine.sh

128 lines · 3659 bytes Raw Blame History
1#!/bin/sh
2
3test_description='check quarantine of objects during push'
4
5. ./test-lib.sh
6
7test_expect_success 'create picky dest repo' '
8 git init --bare dest.git &&
9 test_hook --setup -C dest.git pre-receive <<-\EOF
10 while read old new ref; do
11 test "$(git log -1 --format=%s $new)" = reject && exit 1
12 done
13 exit 0
14 EOF
15'
16
17test_expect_success 'accepted objects work' '
18 test_commit ok &&
19 git push dest.git HEAD &&
20 commit=$(git rev-parse HEAD) &&
21 git --git-dir=dest.git cat-file commit $commit
22'
23
24test_expect_success 'rejected objects are not installed' '
25 test_commit reject &&
26 commit=$(git rev-parse HEAD) &&
27 test_must_fail git push dest.git reject &&
28 test_must_fail git --git-dir=dest.git cat-file commit $commit
29'
30
31test_expect_success 'rejected objects are removed' '
32 echo "incoming-*" >expect &&
33 (cd dest.git/objects && echo incoming-*) >actual &&
34 test_cmp expect actual
35'
36
37test_expect_success 'push to repo path with path separator (colon)' '
38 # The interesting failure case here is when the
39 # receiving end cannot access its original object directory,
40 # so make it likely for us to generate a delta by having
41 # a non-trivial file with multiple versions.
42
43 test-tool genrandom foo 4096 >file.bin &&
44 git add file.bin &&
45 git commit -m bin &&
46
47 if test_have_prereq MINGW
48 then
49 pathsep=";"
50 else
51 pathsep=":"
52 fi &&
53 git clone --bare . "xxx${pathsep}yyy.git" &&
54
55 echo change >>file.bin &&
56 git commit -am change &&
57 # Note that we have to use the full path here, or it gets confused
58 # with the ssh host:path syntax.
59 git push "$(pwd)/xxx${pathsep}yyy.git" HEAD
60'
61
62test_expect_success 'updating a ref from quarantine is forbidden' '
63 git init --bare update.git &&
64 test_hook -C update.git pre-receive <<-\EOF &&
65 read old new refname
66 git update-ref refs/heads/unrelated $new
67 exit 1
68 EOF
69 test_must_fail git push update.git HEAD &&
70 git -C update.git fsck
71'
72
73test_expect_success '.keep file is removed after push' '
74 test_when_finished rm -rf keep.git &&
75 git init --bare keep.git &&
76
77 git -C keep.git config set receive.unpackLimit 0 &&
78
79 # While incoming objects are still quarantined, validate that the
80 # ".keep" lockfile is not present in the quarantine directory.
81 test_hook -C keep.git pre-receive <<-\EOF &&
82 test ! -e "$GIT_QUARANTINE_PATH"/pack/pack-*.keep
83 EOF
84
85 # After quarantined objects are migrated, validate that the ".keep"
86 # lockfile is migrated and present in the main ODB.
87 test_hook -C keep.git reference-transaction <<-\EOF &&
88 keep="$(ls objects/pack/pack-*.keep)" &&
89 test -f "$keep"
90 EOF
91
92 test_commit foo &&
93 git push keep.git HEAD &&
94
95 # Once the operation is complete, validate that the ".keep" lockfile has
96 # been removed.
97 pack="$(ls keep.git/objects/pack/pack-*.pack)" &&
98 keep="${pack%.pack}.keep" &&
99 test_path_is_file "$pack" &&
100 test_path_is_missing "$keep"
101'
102
103test_expect_success '.keep file created outside of process is not removed' '
104 test_when_finished rm -rf keep.git &&
105 git init --bare keep.git &&
106
107 git -C keep.git config set receive.unpackLimit 0 &&
108
109 # Create a ".keep" lockfile matching the packfile to simulate a
110 # concurrent git-receive-pack(1) that has already written its lockfile.
111 test_hook -C keep.git pre-receive <<-\EOF &&
112 pack="$(ls "$GIT_QUARANTINE_PATH"/pack/pack-*.pack)" &&
113 pack="${pack##*/}" &&
114 echo "baz" >"objects/pack/${pack%.pack}.keep"
115 EOF
116
117 test_commit bar &&
118 test_must_fail git push keep.git HEAD &&
119
120 # The ".keep" lockfile of the concurrent git-receive-pack(1) should be
121 # left in its place.
122 keep="$(ls keep.git/objects/pack/pack-*.keep)" &&
123 test_path_is_file "$keep" &&
124 test_grep "baz" "$keep" &&
125 test_path_is_missing "${keep%.keep}.pack"
126'
127
128test_done