]> git.proxmox.com Git - libgit2.git/blobdiff - src/fetchhead.c
remote: create FETCH_HEAD with a refspecless remote
[libgit2.git] / src / fetchhead.c
index 14878feb504ca19d9238808c464913c45f5746a6..77aafc8f36cf1e33945589256c33094be4d15d75 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2012 the libgit2 contributors
+ * Copyright (C) the libgit2 contributors. All rights reserved.
  *
  * This file is part of libgit2, distributed under the GNU GPL v2 with
  * a Linking Exception. For full terms see the included COPYING file.
@@ -16,7 +16,6 @@
 #include "refs.h"
 #include "repository.h"
 
-
 int git_fetchhead_ref_cmp(const void *a, const void *b)
 {
        const git_fetchhead_ref *one = (const git_fetchhead_ref *)a;
@@ -75,6 +74,7 @@ static int fetchhead_ref_write(
 {
        char oid[GIT_OID_HEXSZ + 1];
        const char *type, *name;
+       int head = 0;
 
        assert(file && fetchhead_ref);
 
@@ -88,11 +88,16 @@ static int fetchhead_ref_write(
                GIT_REFS_TAGS_DIR) == 0) {
                type = "tag ";
                name = fetchhead_ref->ref_name + strlen(GIT_REFS_TAGS_DIR);
+       } else if (!git__strcmp(fetchhead_ref->ref_name, GIT_HEAD_FILE)) {
+               head = 1;
        } else {
                type = "";
                name = fetchhead_ref->ref_name;
        }
 
+       if (head)
+               return git_filebuf_printf(file, "%s\t\t%s\n", oid, fetchhead_ref->remote_url);
+
        return git_filebuf_printf(file, "%s\t%s\t%s'%s' of %s\n",
                oid,
                (fetchhead_ref->is_merge) ? "" : "not-for-merge",
@@ -237,7 +242,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
        const char *ref_name;
        git_oid oid;
        const char *remote_url;
-       unsigned int is_merge;
+       unsigned int is_merge = 0;
        char *buffer, *line;
        size_t line_num = 0;
        int error = 0;