Skip to content

Commit f2c681c

Browse files
pcloudsgitster
authored andcommitted
send-pack: support pushing from a shallow clone via http
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c29a7b8 commit f2c681c

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

builtin/send-pack.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
209209
(send_all && args.send_mirror))
210210
usage(send_pack_usage);
211211

212-
if (is_repository_shallow() && args.stateless_rpc)
213-
die("attempt to push from a shallow repository");
214-
215212
if (remote_name) {
216213
remote = remote_get(remote_name);
217214
if (!remote_has_url(remote, dest)) {

send-pack.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ static int sideband_demux(int in, int out, void *data)
175175
return ret;
176176
}
177177

178+
static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
179+
{
180+
struct strbuf *sb = cb;
181+
if (graft->nr_parent == -1)
182+
packet_buf_write(sb, "shallow %s\n", sha1_to_hex(graft->sha1));
183+
return 0;
184+
}
185+
186+
void advertise_shallow_grafts_buf(struct strbuf *sb)
187+
{
188+
if (!is_repository_shallow())
189+
return;
190+
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
191+
}
192+
178193
int send_pack(struct send_pack_args *args,
179194
int fd[], struct child_process *conn,
180195
struct ref *remote_refs,
@@ -215,7 +230,7 @@ int send_pack(struct send_pack_args *args,
215230
}
216231

217232
if (!args->dry_run)
218-
advertise_shallow_grafts(out);
233+
advertise_shallow_grafts_buf(&req_buf);
219234

220235
/*
221236
* Finally, tell the other end!
@@ -276,7 +291,7 @@ int send_pack(struct send_pack_args *args,
276291
}
277292

278293
if (args->stateless_rpc) {
279-
if (!args->dry_run && cmds_sent) {
294+
if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
280295
packet_buf_flush(&req_buf);
281296
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
282297
}

t/t5538-push-shallow.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,30 @@ EOF
154154
)
155155
'
156156

157+
test_expect_success 'push from shallow repo via http' '
158+
mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git &&
159+
git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
160+
(
161+
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
162+
git config http.receivepack true
163+
) &&
164+
commit 10 &&
165+
git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master &&
166+
(
167+
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
168+
git fsck &&
169+
git log --format=%s top/master >actual &&
170+
cat <<EOF >expect &&
171+
10
172+
1
173+
4
174+
3
175+
2
176+
1
177+
EOF
178+
test_cmp expect actual
179+
)
180+
'
181+
157182
stop_httpd
158183
test_done

0 commit comments

Comments
 (0)