Skip to content

Commit aab179d

Browse files
ttaylorrpeff
authored andcommitted
builtin/clone.c: don't ignore transport_fetch_refs() errors
If 'git clone' couldn't execute 'transport_fetch_refs()' (e.g., because of an error on the remote's side in 'git upload-pack'), then it will silently ignore it. Even though this has been the case at least since clone was ported to C (way back in 8434c2f (Build in clone, 2008-04-27)), 'git fetch' doesn't ignore these and reports any failures it sees. That suggests that ignoring the return value in 'git clone' is simply an oversight that should be corrected. That's exactly what this patch does. (Noticing and fixing this is no coincidence, we'll want it in the next patch in order to demonstrate a regression in 'git upload-pack' via a 'git clone'.) There's no additional logging here, but that matches how 'git fetch' handles the same case. An assumption there is that whichever part of transport_fetch_refs() fails will complain loudly, so any additional logging here is redundant. Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a0b884 commit aab179d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

builtin/clone.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12931293
break;
12941294
}
12951295

1296-
if (!is_local && !complete_refs_before_fetch)
1297-
transport_fetch_refs(transport, mapped_refs);
1296+
if (!is_local && !complete_refs_before_fetch) {
1297+
err = transport_fetch_refs(transport, mapped_refs);
1298+
if (err)
1299+
goto cleanup;
1300+
}
12981301

12991302
remote_head = find_ref_by_name(refs, "HEAD");
13001303
remote_head_points_at =
@@ -1339,8 +1342,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13391342

13401343
if (is_local)
13411344
clone_local(path, git_dir);
1342-
else if (refs && complete_refs_before_fetch)
1343-
transport_fetch_refs(transport, mapped_refs);
1345+
else if (refs && complete_refs_before_fetch) {
1346+
err = transport_fetch_refs(transport, mapped_refs);
1347+
if (err)
1348+
goto cleanup;
1349+
}
13441350

13451351
update_remote_refs(refs, mapped_refs, remote_head_points_at,
13461352
branch_top.buf, reflog_msg.buf, transport,
@@ -1367,6 +1373,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13671373
junk_mode = JUNK_LEAVE_REPO;
13681374
err = checkout(submodule_progress);
13691375

1376+
cleanup:
13701377
free(remote_name);
13711378
strbuf_release(&reflog_msg);
13721379
strbuf_release(&branch_top);

0 commit comments

Comments
 (0)