commit 55ff12a650e3bd5e4a81811caf98904a627c59e3 from: Martijn van Duren via: Stefan Sperling date: Sat Jul 12 09:18:53 2025 UTC pick a default branch to clone when the server does not advertise HEAD symref Avoids the need to use got clone -b to get anything at all from a server implementation which does not advertise a HEAD symref. Patch by martijn@ commit - fe389d9e9b32033b8ea536ca04677a62243d42a7 commit + 55ff12a650e3bd5e4a81811caf98904a627c59e3 blob - 736c8e342f847a5c286727292fe961ed4fcac388 blob + 78332997dbcd1bbcf19dda1a4540702bf27094d6 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -351,6 +351,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, char *id_str = NULL, *default_id_str = NULL, *refname = NULL; char *server_capabilities = NULL, *my_capabilities = NULL; const char *default_branch = NULL; + char *free_default_branch = NULL; struct got_pathlist_head symrefs; struct got_pathlist_entry *pe; int sent_my_capabilites = 0, have_sidebands = 0; @@ -434,6 +435,14 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, continue; default_branch = symref_target; break; + } + if (default_branch == NULL) { + default_id_str = strdup(id_str); + if (default_id_str == NULL) { + err = got_error_from_errno( + "strdup"); + goto done; + } } } if (default_branch) @@ -454,6 +463,17 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, goto done; } } + /* If no symrefs is given, go for first matching id_str */ + if (default_branch == NULL && default_id_str && + strncmp(refname, "refs/heads/", 11) == 0 && + strcmp(id_str, default_id_str) == 0) { + free_default_branch = strdup(refname); + if (free_default_branch == NULL) { + err = got_error_from_errno("strdup"); + goto done; + } + default_branch = free_default_branch; + } if (list_refs_only || strncmp(refname, "refs/tags/", 10) == 0) { err = fetch_ref(ibuf, have_refs, &have[nref], @@ -846,6 +866,7 @@ done: free(have); free(want); free(id_str); + free(free_default_branch); free(default_id_str); free(refname); free(server_capabilities);