summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-12-28 10:38:31 +0000
committerGitHub <noreply@github.com>2017-12-28 10:38:31 +0000
commit083b1a2e2d8d190db02db3db0dad4fa742eccb02 (patch)
tree9d1a4285c20999482501ba01be484ba8e402ab2e /src
parent4110fc8444080aa50449630b634d7337c30924b8 (diff)
parentc081f0d00dd2a2cd2aab7175cd2c65413f1cf52a (diff)
downloadlibgit2-083b1a2e2d8d190db02db3db0dad4fa742eccb02.tar.gz
Merge pull request #4021 from carlosmn/cmn/refspecs-fetchhead
FETCH_HEAD and multiple refspecs
Diffstat (limited to 'src')
-rw-r--r--src/fetchhead.c2
-rw-r--r--src/fileops.c10
-rw-r--r--src/fileops.h5
-rw-r--r--src/remote.c17
4 files changed, 33 insertions, 1 deletions
diff --git a/src/fetchhead.c b/src/fetchhead.c
index ac25723d3..e55e7c85b 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -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)
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);
return -1;
}
diff --git a/src/fileops.c b/src/fileops.c
index ad3f67e2b..58988c2d2 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -102,6 +102,16 @@ int git_futils_open_ro(const char *path)
return fd;
}
+int git_futils_truncate(const char *path, int mode)
+{
+ int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
+ if (fd < 0)
+ return git_path_set_error(errno, path, "open");
+
+ close(fd);
+ return 0;
+}
+
git_off_t git_futils_filesize(git_file fd)
{
struct stat sb;
diff --git a/src/fileops.h b/src/fileops.h
index fd5441243..57b9d173e 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -248,6 +248,11 @@ extern int git_futils_cp_r(
extern int git_futils_open_ro(const char *path);
/**
+ * Truncate a file, creating it if it doesn't exist.
+ */
+extern int git_futils_truncate(const char *path, int mode);
+
+/**
* Get the filesize in bytes of a file
*/
extern git_off_t git_futils_filesize(git_file fd);
diff --git a/src/remote.c b/src/remote.c
index 303911760..4d675af82 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1541,6 +1541,20 @@ cleanup:
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(
git_remote *remote,
const git_remote_callbacks *callbacks,
@@ -1571,6 +1585,9 @@ int git_remote_update_tips(
else
tagopt = download_tags;
+ if ((error = truncate_fetch_head(git_repository_path(remote->repo))) < 0)
+ goto out;
+
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, &tagspec, &refs, reflog_message)) < 0)
goto out;