blame documentation: -M/-C notice copied lines as well as moved ones
[gitweb.git] / builtin-fetch.c
index 8654fa7a2dbe2c1ca76a493a4322447de5219b99..007dabf62f2574fc9214d6fb2a961619ad305a6b 100644 (file)
 #include "sigchain.h"
 
 static const char * const builtin_fetch_usage[] = {
-       "git fetch [options] [<repository> <refspec>...]",
-       "git fetch [options] <group>",
-       "git fetch --multiple [options] [<repository> | <group>]...",
-       "git fetch --all [options]",
+       "git fetch [<options>] [<repository> [<refspec>...]]",
+       "git fetch [<options>] <group>",
+       "git fetch --multiple [<options>] [<repository> | <group>]...",
+       "git fetch --all [<options>]",
        NULL
 };
 
@@ -104,10 +104,8 @@ static void add_merge_config(struct ref **head,
                 * there is no entry in the resulting FETCH_HEAD marked
                 * for merging.
                 */
+               memset(&refspec, 0, sizeof(refspec));
                refspec.src = branch->merge[i]->src;
-               refspec.dst = NULL;
-               refspec.pattern = 0;
-               refspec.force = 0;
                get_fetch_map(remote_refs, &refspec, tail, 1);
                for (rm = *old_tail; rm; rm = rm->next)
                        rm->merge = 1;
@@ -389,9 +387,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                fputc(url[i], fp);
                fputc('\n', fp);
 
-               if (ref)
+               if (ref) {
                        rc |= update_local_ref(ref, what, note);
-               else
+                       free(ref);
+               } else
                        sprintf(note, "* %-*s %-*s -> FETCH_HEAD",
                                SUMMARY_WIDTH, *kind ? kind : "branch",
                                 REFCOL_WIDTH, *what ? what : "HEAD");
@@ -588,7 +587,7 @@ static void find_non_local_tags(struct transport *transport,
                 * to fetch then we can mark the ref entry in the list
                 * as one to ignore by setting util to NULL.
                 */
-               if (!strcmp(ref->name + strlen(ref->name) - 3, "^{}")) {
+               if (!suffixcmp(ref->name, "^{}")) {
                        if (item && !has_sha1_file(ref->old_sha1) &&
                            !will_fetch(head, ref->old_sha1) &&
                            !has_sha1_file(item->util) &&
@@ -651,6 +650,17 @@ static void check_not_current_branch(struct ref *ref_map)
                            "of non-bare repository", current_branch->refname);
 }
 
+static int truncate_fetch_head(void)
+{
+       char *filename = git_path("FETCH_HEAD");
+       FILE *fp = fopen(filename, "w");
+
+       if (!fp)
+               return error("cannot open %s: %s\n", filename, strerror(errno));
+       fclose(fp);
+       return 0;
+}
+
 static int do_fetch(struct transport *transport,
                    struct refspec *refs, int ref_count)
 {
@@ -672,11 +682,9 @@ static int do_fetch(struct transport *transport,
 
        /* if not appending, truncate FETCH_HEAD */
        if (!append && !dry_run) {
-               char *filename = git_path("FETCH_HEAD");
-               FILE *fp = fopen(filename, "w");
-               if (!fp)
-                       return error("cannot open %s: %s\n", filename, strerror(errno));
-               fclose(fp);
+               int errcode = truncate_fetch_head();
+               if (errcode)
+                       return errcode;
        }
 
        ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
@@ -784,13 +792,19 @@ static int add_remote_or_group(const char *name, struct string_list *list)
 static int fetch_multiple(struct string_list *list)
 {
        int i, result = 0;
-       const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL, NULL };
-       int argc = 1;
+       const char *argv[11] = { "fetch", "--append" };
+       int argc = 2;
 
        if (dry_run)
                argv[argc++] = "--dry-run";
        if (prune)
                argv[argc++] = "--prune";
+       if (update_head_ok)
+               argv[argc++] = "--update-head-ok";
+       if (force)
+               argv[argc++] = "--force";
+       if (keep)
+               argv[argc++] = "--keep";
        if (verbosity >= 2)
                argv[argc++] = "-v";
        if (verbosity >= 1)
@@ -798,9 +812,16 @@ static int fetch_multiple(struct string_list *list)
        else if (verbosity < 0)
                argv[argc++] = "-q";
 
+       if (!append && !dry_run) {
+               int errcode = truncate_fetch_head();
+               if (errcode)
+                       return errcode;
+       }
+
        for (i = 0; i < list->nr; i++) {
                const char *name = list->items[i].string;
                argv[argc] = name;
+               argv[argc + 1] = NULL;
                if (verbosity >= 0)
                        printf("Fetching %s\n", name);
                if (run_command_v_opt(argv, RUN_GIT_CMD)) {