diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-06-14 13:33:26 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-06-14 13:33:26 +0900 |
commit | f4f7304b443a52af9fdbbf15092516c061de4aeb (patch) | |
tree | a739f2b1b3ae7a1611a8423104bcc1f13915c80f | |
parent | Merge branch 'ga/send-email-sendmail-cmd' (diff) | |
parent | clone: clean up directory after transport_fetch_refs() failure (diff) | |
download | tgif-f4f7304b443a52af9fdbbf15092516c061de4aeb.tar.xz |
Merge branch 'jk/clone-clean-upon-transport-error'
Recent "git clone" left a temporary directory behind when the
transport layer returned an failure.
* jk/clone-clean-upon-transport-error:
clone: clean up directory after transport_fetch_refs() failure
-rw-r--r-- | builtin/clone.c | 11 | ||||
-rwxr-xr-x | t/t5600-clone-fail-cleanup.sh | 7 |
2 files changed, 11 insertions, 7 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index eeb74c0217..66fe66679c 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1320,9 +1320,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } if (!is_local && !complete_refs_before_fetch) { - err = transport_fetch_refs(transport, mapped_refs); - if (err) - goto cleanup; + if (transport_fetch_refs(transport, mapped_refs)) + die(_("remote transport reported error")); } remote_head = find_ref_by_name(refs, "HEAD"); @@ -1380,9 +1379,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (is_local) clone_local(path, git_dir); else if (refs && complete_refs_before_fetch) { - err = transport_fetch_refs(transport, mapped_refs); - if (err) - goto cleanup; + if (transport_fetch_refs(transport, mapped_refs)) + die(_("remote transport reported error")); } update_remote_refs(refs, mapped_refs, remote_head_points_at, @@ -1410,7 +1408,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) junk_mode = JUNK_LEAVE_REPO; err = checkout(submodule_progress); -cleanup: free(remote_name); strbuf_release(&reflog_msg); strbuf_release(&branch_top); diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 4a1a912e03..5bf10261d3 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -97,4 +97,11 @@ test_expect_success 'failed clone into empty leaves directory (separate, wt)' ' test_dir_is_empty empty-wt ' +test_expect_success 'transport failure cleans up directory' ' + test_must_fail git clone --no-local \ + -u "f() { git-upload-pack \"\$@\"; return 1; }; f" \ + foo broken-clone && + test_path_is_missing broken-clone +' + test_done |