Commit 1b4fbf2e by Carlos Martín Nieto

remote: append to FETCH_HEAD rather than overwrite for each refspec

We treat each refspec on its own, but the code currently overwrites the contents
of FETCH_HEAD so we end up with the entries for the last refspec we processed.

Instead, truncate it before performing the updates and append to it when
updating the references.
parent 3ccc1a4d
...@@ -118,7 +118,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs) ...@@ -118,7 +118,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0) if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1; return -1;
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) { if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) {
git_buf_free(&path); git_buf_free(&path);
return -1; return -1;
} }
......
...@@ -1541,6 +1541,20 @@ cleanup: ...@@ -1541,6 +1541,20 @@ cleanup:
return error; return error;
} }
static int truncate_fetch_head(const char *gitdir)
{
git_buf path = GIT_BUF_INIT;
int error;
if ((error = git_buf_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
return error;
error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE);
git_buf_free(&path);
return error;
}
int git_remote_update_tips( int git_remote_update_tips(
git_remote *remote, git_remote *remote,
const git_remote_callbacks *callbacks, const git_remote_callbacks *callbacks,
...@@ -1571,6 +1585,9 @@ int git_remote_update_tips( ...@@ -1571,6 +1585,9 @@ int git_remote_update_tips(
else else
tagopt = download_tags; tagopt = download_tags;
if ((error = truncate_fetch_head(git_repository_path(remote->repo))) < 0)
goto out;
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) { if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, &tagspec, &refs, reflog_message)) < 0) if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, &tagspec, &refs, reflog_message)) < 0)
goto out; goto out;
......
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