Skip to content

Commit 1b4fbf2

Browse files
committed
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.
1 parent 3ccc1a4 commit 1b4fbf2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/fetchhead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
118118
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
119119
return -1;
120120

121-
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) {
121+
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) {
122122
git_buf_free(&path);
123123
return -1;
124124
}

src/remote.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,20 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
15411541
return error;
15421542
}
15431543

1544+
static int truncate_fetch_head(const char *gitdir)
1545+
{
1546+
git_buf path = GIT_BUF_INIT;
1547+
int error;
1548+
1549+
if ((error = git_buf_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
1550+
return error;
1551+
1552+
error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE);
1553+
git_buf_free(&path);
1554+
1555+
return error;
1556+
}
1557+
15441558
int git_remote_update_tips(
15451559
git_remote *remote,
15461560
const git_remote_callbacks *callbacks,
@@ -1571,6 +1585,9 @@ int git_remote_update_tips(
15711585
else
15721586
tagopt = download_tags;
15731587

1588+
if ((error = truncate_fetch_head(git_repository_path(remote->repo))) < 0)
1589+
goto out;
1590+
15741591
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
15751592
if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, &tagspec, &refs, reflog_message)) < 0)
15761593
goto out;

0 commit comments

Comments
 (0)