Commit 517bda19 by Carlos Martín Nieto

fetch: store FETCH_HEAD

We should always save the remote's HEAD as FETCH_HEAD locally.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent 4a3b18a6
...@@ -24,7 +24,7 @@ static int filter_wants(git_remote *remote) ...@@ -24,7 +24,7 @@ static int filter_wants(git_remote *remote)
git_repository *repo = remote->repo; git_repository *repo = remote->repo;
const git_refspec *spec; const git_refspec *spec;
int error; int error;
unsigned int i; unsigned int i = 0;
error = git_vector_init(&list, 16, NULL); error = git_vector_init(&list, 16, NULL);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
...@@ -44,7 +44,24 @@ static int filter_wants(git_remote *remote) ...@@ -44,7 +44,24 @@ static int filter_wants(git_remote *remote)
*/ */
spec = git_remote_fetchspec(remote); spec = git_remote_fetchspec(remote);
for (i = 0; i < refs.len; ++i) { /*
* We need to handle HEAD separately, as we always want it, but it
* probably won't matcht he refspec.
*/
head = refs.heads[0];
if (refs.len > 0 && !strcmp(head->name, GIT_HEAD_FILE)) {
if (git_odb_exists(repo->db, &head->oid))
head->local = 1;
else
remote->need_pack = 1;
i = 1;
error = git_vector_insert(&list, refs.heads[0]);
if (error < GIT_SUCCESS)
goto cleanup;
}
for (; i < refs.len; ++i) {
git_remote_head *head = refs.heads[i]; git_remote_head *head = refs.heads[i];
/* If it doesn't match the refpec, we don't want it */ /* If it doesn't match the refpec, we don't want it */
......
...@@ -1713,7 +1713,8 @@ static int normalize_name(char *buffer_out, size_t out_size, const char *name, i ...@@ -1713,7 +1713,8 @@ static int normalize_name(char *buffer_out, size_t out_size, const char *name, i
/* Object id refname have to contain at least one slash, except /* Object id refname have to contain at least one slash, except
* for HEAD in a detached state or MERGE_HEAD if we're in the * for HEAD in a detached state or MERGE_HEAD if we're in the
* middle of a merge */ * middle of a merge */
if (is_oid_ref && !contains_a_slash && (strcmp(name, GIT_HEAD_FILE) && strcmp(name, GIT_MERGE_HEAD_FILE))) if (is_oid_ref && !contains_a_slash && (strcmp(name, GIT_HEAD_FILE) && strcmp(name, GIT_MERGE_HEAD_FILE)
&& strcmp(name, GIT_FETCH_HEAD_FILE)))
return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains no slashes"); return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains no slashes");
/* A refname can not end with ".lock" */ /* A refname can not end with ".lock" */
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled " #define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled "
#define GIT_HEAD_FILE "HEAD" #define GIT_HEAD_FILE "HEAD"
#define GIT_FETCH_HEAD_FILE "FETCH_HEAD"
#define GIT_MERGE_HEAD_FILE "MERGE_HEAD" #define GIT_MERGE_HEAD_FILE "MERGE_HEAD"
#define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master" #define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
......
...@@ -219,7 +219,7 @@ int git_remote_download(char **filename, git_remote *remote) ...@@ -219,7 +219,7 @@ int git_remote_download(char **filename, git_remote *remote)
int git_remote_update_tips(struct git_remote *remote) int git_remote_update_tips(struct git_remote *remote)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
unsigned int i; unsigned int i = 0;
char refname[GIT_PATH_MAX]; char refname[GIT_PATH_MAX];
git_headarray *refs = &remote->refs; git_headarray *refs = &remote->refs;
git_remote_head *head; git_remote_head *head;
...@@ -228,8 +228,21 @@ int git_remote_update_tips(struct git_remote *remote) ...@@ -228,8 +228,21 @@ int git_remote_update_tips(struct git_remote *remote)
memset(refname, 0x0, sizeof(refname)); memset(refname, 0x0, sizeof(refname));
for (i = 0; i < refs->len; ++i) { if (refs->len == 0)
return GIT_SUCCESS;
/* HEAD is only allowed to be the first in the list */
head = refs->heads[0];
if (!strcmp(head->name, GIT_HEAD_FILE)) {
error = git_reference_create_oid(&ref, remote->repo, GIT_FETCH_HEAD_FILE, &head->oid, 1);
i = 1;
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to update FETCH_HEAD");
}
for (; i < refs->len; ++i) {
head = refs->heads[i]; head = refs->heads[i];
error = git_refspec_transform(refname, sizeof(refname), spec, head->name); error = git_refspec_transform(refname, sizeof(refname), spec, head->name);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment