@@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
11
11
HOOK=" $HOOKDIR /pre-push"
12
12
mkdir -p " $HOOKDIR "
13
13
write_script " $HOOK " << EOF
14
- cat >/dev/null
14
+ cat >actual
15
15
exit 0
16
16
EOF
17
17
@@ -20,10 +20,16 @@ test_expect_success 'setup' '
20
20
git init --bare repo1 &&
21
21
git remote add parent1 repo1 &&
22
22
test_commit one &&
23
- git push parent1 HEAD:foreign
23
+ cat >expect <<-EOF &&
24
+ HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
25
+ EOF
26
+
27
+ test_when_finished "rm actual" &&
28
+ git push parent1 HEAD:foreign &&
29
+ test_cmp expect actual
24
30
'
25
31
write_script " $HOOK " << EOF
26
- cat >/dev/null
32
+ cat >actual
27
33
exit 1
28
34
EOF
29
35
@@ -32,11 +38,18 @@ export COMMIT1
32
38
33
39
test_expect_success ' push with failing hook' '
34
40
test_commit two &&
35
- test_must_fail git push parent1 HEAD
41
+ cat >expect <<-EOF &&
42
+ HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
43
+ EOF
44
+
45
+ test_when_finished "rm actual" &&
46
+ test_must_fail git push parent1 HEAD &&
47
+ test_cmp expect actual
36
48
'
37
49
38
50
test_expect_success ' --no-verify bypasses hook' '
39
- git push --no-verify parent1 HEAD
51
+ git push --no-verify parent1 HEAD &&
52
+ test_path_is_missing actual
40
53
'
41
54
42
55
COMMIT2=" $( git rev-parse HEAD) "
@@ -48,15 +61,15 @@ echo "$2" >>actual
48
61
cat >>actual
49
62
EOF
50
63
51
- cat > expected << EOF
52
- parent1
53
- repo1
54
- refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
55
- EOF
56
-
57
64
test_expect_success ' push with hook' '
65
+ cat >expect <<-EOF &&
66
+ parent1
67
+ repo1
68
+ refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
69
+ EOF
70
+
58
71
git push parent1 main:foreign &&
59
- diff expected actual
72
+ test_cmp expect actual
60
73
'
61
74
62
75
test_expect_success ' add a branch' '
@@ -67,49 +80,48 @@ test_expect_success 'add a branch' '
67
80
COMMIT3=" $( git rev-parse HEAD) "
68
81
export COMMIT3
69
82
70
- cat > expected << EOF
71
- parent1
72
- repo1
73
- refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
74
- EOF
75
-
76
83
test_expect_success ' push to default' '
84
+ cat >expect <<-EOF &&
85
+ parent1
86
+ repo1
87
+ refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
88
+ EOF
77
89
git push &&
78
- diff expected actual
90
+ test_cmp expect actual
79
91
'
80
92
81
- cat > expected << EOF
82
- parent1
83
- repo1
84
- refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
85
- HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
86
- EOF
87
-
88
93
test_expect_success ' push non-branches' '
94
+ cat >expect <<-EOF &&
95
+ parent1
96
+ repo1
97
+ refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
98
+ HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
99
+ EOF
100
+
89
101
git push parent1 one:tag1 HEAD~:refs/heads/prev &&
90
- diff expected actual
102
+ test_cmp expect actual
91
103
'
92
104
93
- cat > expected << EOF
94
- parent1
95
- repo1
96
- (delete) $ZERO_OID refs/heads/prev $COMMIT2
97
- EOF
98
-
99
105
test_expect_success ' push delete' '
106
+ cat >expect <<-EOF &&
107
+ parent1
108
+ repo1
109
+ (delete) $ZERO_OID refs/heads/prev $COMMIT2
110
+ EOF
111
+
100
112
git push parent1 :prev &&
101
- diff expected actual
113
+ test_cmp expect actual
102
114
'
103
115
104
- cat > expected << EOF
105
- repo1
106
- repo1
107
- HEAD $COMMIT3 refs/heads/other $ZERO_OID
108
- EOF
109
-
110
116
test_expect_success ' push to URL' '
117
+ cat >expect <<-EOF &&
118
+ repo1
119
+ repo1
120
+ HEAD $COMMIT3 refs/heads/other $ZERO_OID
121
+ EOF
122
+
111
123
git push repo1 HEAD &&
112
- diff expected actual
124
+ test_cmp expect actual
113
125
'
114
126
115
127
test_expect_success ' set up many-ref tests' '
0 commit comments