Skip to content

Commit

Permalink
send-pack: support pushing from a shallow clone via http
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Dec 11, 2013
1 parent c29a7b8 commit f2c681c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
3 changes: 0 additions & 3 deletions builtin/send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
(send_all && args.send_mirror))
usage(send_pack_usage);

if (is_repository_shallow() && args.stateless_rpc)
die("attempt to push from a shallow repository");

if (remote_name) {
remote = remote_get(remote_name);
if (!remote_has_url(remote, dest)) {
Expand Down
19 changes: 17 additions & 2 deletions send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ static int sideband_demux(int in, int out, void *data)
return ret;
}

static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
{
struct strbuf *sb = cb;
if (graft->nr_parent == -1)
packet_buf_write(sb, "shallow %s\n", sha1_to_hex(graft->sha1));
return 0;
}

void advertise_shallow_grafts_buf(struct strbuf *sb)
{
if (!is_repository_shallow())
return;
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
}

int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs,
Expand Down Expand Up @@ -215,7 +230,7 @@ int send_pack(struct send_pack_args *args,
}

if (!args->dry_run)
advertise_shallow_grafts(out);
advertise_shallow_grafts_buf(&req_buf);

/*
* Finally, tell the other end!
Expand Down Expand Up @@ -276,7 +291,7 @@ int send_pack(struct send_pack_args *args,
}

if (args->stateless_rpc) {
if (!args->dry_run && cmds_sent) {
if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
packet_buf_flush(&req_buf);
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
}
Expand Down
25 changes: 25 additions & 0 deletions t/t5538-push-shallow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,30 @@ EOF
)
'

test_expect_success 'push from shallow repo via http' '
mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git &&
git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
(
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
git config http.receivepack true
) &&
commit 10 &&
git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master &&
(
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
git fsck &&
git log --format=%s top/master >actual &&
cat <<EOF >expect &&
10
1
4
3
2
1
EOF
test_cmp expect actual
)
'

stop_httpd
test_done

0 comments on commit f2c681c

Please sign in to comment.