@@ -32,9 +32,7 @@ test_expect_success setup '
32
32
done &&
33
33
git update-ref HEAD "$commit" &&
34
34
git clone ./. victim &&
35
- cd victim &&
36
- git log &&
37
- cd .. &&
35
+ ( cd victim && git log ) &&
38
36
git update-ref HEAD "$zero" &&
39
37
parent=$zero &&
40
38
i=0 &&
@@ -59,88 +57,84 @@ test_expect_success 'pack the source repository' '
59
57
'
60
58
61
59
test_expect_success ' pack the destination repository' '
60
+ (
62
61
cd victim &&
63
62
git repack -a -d &&
64
- git prune &&
65
- cd ..
63
+ git prune
64
+ )
66
65
'
67
66
68
- test_expect_success \
69
- ' pushing rewound head should not barf but require --force' '
70
- # should not fail but refuse to update.
71
- if git send-pack ./victim/.git/ master
72
- then
73
- # now it should fail with Pasky patch
74
- echo >&2 Gaah, it should have failed.
75
- false
76
- else
77
- echo >&2 Thanks, it correctly failed.
78
- true
79
- fi &&
80
- if cmp victim/.git/refs/heads/master .git/refs/heads/master
81
- then
82
- # should have been left as it was!
83
- false
84
- else
85
- true
86
- fi &&
67
+ test_expect_success ' refuse pushing rewound head without --force' '
68
+ pushed_head=$(git rev-parse --verify master) &&
69
+ victim_orig=$(cd victim && git rev-parse --verify master) &&
70
+ test_must_fail git send-pack ./victim master &&
71
+ victim_head=$(cd victim && git rev-parse --verify master) &&
72
+ test "$victim_head" = "$victim_orig" &&
87
73
# this should update
88
- git send-pack --force ./victim/.git/ master &&
89
- cmp victim/.git/refs/heads/master .git/refs/heads/master
74
+ git send-pack --force ./victim master &&
75
+ victim_head=$(cd victim && git rev-parse --verify master) &&
76
+ test "$victim_head" = "$pushed_head"
90
77
'
91
78
92
79
test_expect_success \
93
80
' push can be used to delete a ref' '
94
- cd victim &&
95
- git branch extra master &&
96
- cd .. &&
97
- test -f victim/.git/refs/heads/extra &&
98
- git send-pack ./victim/.git/ :extra master &&
99
- ! test -f victim/.git/refs/heads/extra
81
+ ( cd victim && git branch extra master ) &&
82
+ git send-pack ./victim :extra master &&
83
+ ( cd victim &&
84
+ test_must_fail git rev-parse --verify extra )
100
85
'
101
86
102
- unset GIT_CONFIG
103
- HOME=` pwd` /no-such-directory
104
- export HOME ; # this way we force the victim/.git/config to be used.
105
-
106
- test_expect_success \
107
- ' pushing a delete should be denied with denyDeletes' '
108
- cd victim &&
109
- git config receive.denyDeletes true &&
110
- git branch extra master &&
111
- cd .. &&
112
- test -f victim/.git/refs/heads/extra &&
113
- test_must_fail git send-pack ./victim/.git/ :extra master
87
+ test_expect_success ' refuse deleting push with denyDeletes' '
88
+ (
89
+ cd victim &&
90
+ ( git branch -D extra || : ) &&
91
+ git config receive.denyDeletes true &&
92
+ git branch extra master
93
+ ) &&
94
+ test_must_fail git send-pack ./victim :extra master
114
95
'
115
- rm -f victim/.git/refs/heads/extra
116
96
117
- test_expect_success \
118
- ' pushing with --force should be denied with denyNonFastforwards' '
119
- cd victim &&
120
- git config receive.denyNonFastforwards true &&
121
- cd .. &&
122
- git update-ref refs/heads/master master^ || return 1
123
- git send-pack --force ./victim/.git/ master && return 1
124
- ! test_cmp .git/refs/heads/master victim/.git/refs/heads/master
97
+ test_expect_success ' denyNonFastforwards trumps --force' '
98
+ (
99
+ cd victim &&
100
+ ( git branch -D extra || : ) &&
101
+ git config receive.denyNonFastforwards true
102
+ ) &&
103
+ victim_orig=$(cd victim && git rev-parse --verify master) &&
104
+ test_must_fail git send-pack --force ./victim master^:master &&
105
+ victim_head=$(cd victim && git rev-parse --verify master) &&
106
+ test "$victim_orig" = "$victim_head"
125
107
'
126
108
127
- test_expect_success \
128
- ' pushing does not include non-head refs' '
129
- mkdir parent && cd parent &&
130
- git init && touch file && git add file && git commit -m add &&
131
- cd .. &&
132
- git clone parent child && cd child && git push --all &&
133
- cd ../parent &&
134
- git branch -a >branches && ! grep origin/master branches
109
+ test_expect_success ' push --all excludes remote tracking hierarchy' '
110
+ mkdir parent &&
111
+ (
112
+ cd parent &&
113
+ git init && : >file && git add file && git commit -m add
114
+ ) &&
115
+ git clone parent child &&
116
+ (
117
+ cd child && git push --all
118
+ ) &&
119
+ (
120
+ cd parent &&
121
+ test -z "$(git for-each-ref refs/remotes/origin)"
122
+ )
135
123
'
136
124
137
125
rewound_push_setup () {
138
126
rm -rf parent child &&
139
- mkdir parent && cd parent &&
140
- git init && echo one > file && git add file && git commit -m one &&
141
- echo two > file && git commit -a -m two &&
142
- cd .. &&
143
- git clone parent child && cd child && git reset --hard HEAD^
127
+ mkdir parent &&
128
+ (
129
+ cd parent &&
130
+ git init &&
131
+ echo one > file && git add file && git commit -m one &&
132
+ echo two > file && git commit -a -m two
133
+ ) &&
134
+ git clone parent child &&
135
+ (
136
+ cd child && git reset --hard HEAD^
137
+ )
144
138
}
145
139
146
140
rewound_push_succeeded () {
@@ -156,30 +150,44 @@ rewound_push_failed() {
156
150
fi
157
151
}
158
152
159
- test_expect_success \
160
- ' pushing explicit refspecs respects forcing' '
153
+ test_expect_success ' pushing explicit refspecs respects forcing' '
161
154
rewound_push_setup &&
162
- if git send-pack ../parent/.git refs/heads/master:refs/heads/master
163
- then
164
- false
165
- else
166
- true
167
- fi && rewound_push_failed &&
168
- git send-pack ../parent/.git +refs/heads/master:refs/heads/master &&
169
- rewound_push_succeeded
155
+ parent_orig=$(cd parent && git rev-parse --verify master) &&
156
+ (
157
+ cd child &&
158
+ test_must_fail git send-pack ../parent \
159
+ refs/heads/master:refs/heads/master
160
+ ) &&
161
+ parent_head=$(cd parent && git rev-parse --verify master) &&
162
+ test "$parent_orig" = "$parent_head" &&
163
+ (
164
+ cd child &&
165
+ git send-pack ../parent \
166
+ +refs/heads/master:refs/heads/master
167
+ ) &&
168
+ parent_head=$(cd parent && git rev-parse --verify master) &&
169
+ child_head=$(cd parent && git rev-parse --verify master) &&
170
+ test "$parent_head" = "$child_head"
170
171
'
171
172
172
- test_expect_success \
173
- ' pushing wildcard refspecs respects forcing' '
173
+ test_expect_success ' pushing wildcard refspecs respects forcing' '
174
174
rewound_push_setup &&
175
- if git send-pack ../parent/.git refs/heads/*:refs/heads/*
176
- then
177
- false
178
- else
179
- true
180
- fi && rewound_push_failed &&
181
- git send-pack ../parent/.git +refs/heads/*:refs/heads/* &&
182
- rewound_push_succeeded
175
+ parent_orig=$(cd parent && git rev-parse --verify master) &&
176
+ (
177
+ cd child &&
178
+ test_must_fail git send-pack ../parent \
179
+ "refs/heads/*:refs/heads/*"
180
+ ) &&
181
+ parent_head=$(cd parent && git rev-parse --verify master) &&
182
+ test "$parent_orig" = "$parent_head" &&
183
+ (
184
+ cd child &&
185
+ git send-pack ../parent \
186
+ "+refs/heads/*:refs/heads/*"
187
+ ) &&
188
+ parent_head=$(cd parent && git rev-parse --verify master) &&
189
+ child_head=$(cd parent && git rev-parse --verify master) &&
190
+ test "$parent_head" = "$child_head"
183
191
'
184
192
185
193
test_done
0 commit comments