Skip to content

Commit b016918

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

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

builtin/send-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
101101
int fd[2];
102102
struct child_process *conn;
103103
struct sha1_array extra_have = SHA1_ARRAY_INIT;
104+
struct sha1_array shallow = SHA1_ARRAY_INIT;
104105
struct ref *remote_refs, *local_refs;
105106
int ret;
106107
int helper_status = 0;
@@ -232,7 +233,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
232233
args.verbose ? CONNECT_VERBOSE : 0);
233234
}
234235

235-
get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have, NULL);
236+
get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL,
237+
&extra_have, &shallow);
236238

237239
transport_verify_remote_names(nr_refspecs, refspecs);
238240

t/t5538-push-shallow.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,42 @@ EOF
8282
test_cmp expect actual
8383
'
8484

85+
test_expect_success 'push from shallow to shallow' '
86+
(
87+
cd shallow &&
88+
git --git-dir=../shallow2/.git config receive.shallowupdate true &&
89+
git push ../shallow2/.git +master:refs/remotes/shallow/master &&
90+
git --git-dir=../shallow2/.git config receive.shallowupdate false
91+
) &&
92+
(
93+
cd shallow2 &&
94+
git log --format=%s shallow/master >actual &&
95+
git fsck &&
96+
cat <<EOF >expect &&
97+
5
98+
4
99+
3
100+
EOF
101+
test_cmp expect actual
102+
)
103+
'
104+
105+
test_expect_success 'push from full to shallow' '
106+
! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` &&
107+
commit 1 &&
108+
git push shallow2/.git +master:refs/remotes/top/master &&
109+
(
110+
cd shallow2 &&
111+
git log --format=%s top/master >actual &&
112+
git fsck &&
113+
cat <<EOF >expect &&
114+
1
115+
4
116+
3
117+
EOF
118+
test_cmp expect actual &&
119+
git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
120+
)
121+
'
122+
85123
test_done

transport.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,10 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
819819
struct ref *tmp_refs;
820820
connect_setup(transport, 1, 0);
821821

822-
get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL, NULL);
822+
get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL,
823+
NULL, &data->shallow);
823824
data->got_remote_heads = 1;
824825
}
825-
if (data->shallow.nr)
826-
die("pushing to a shallow repository is not supported");
827826

828827
memset(&args, 0, sizeof(args));
829828
args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);

0 commit comments

Comments
 (0)