]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-remote.c
Merge branch 'sv/first-parent'
[git.git] / builtin-remote.c
index ca3bf265a93ee457d0069f1379ead105a470745a..8b63619ef08a2ac3d96000908fe4986396ddd6a2 100644 (file)
@@ -19,6 +19,8 @@ static const char * const builtin_remote_usage[] = {
 
 static int verbose;
 
+static int show_all(void);
+
 static inline int postfixcmp(const char *string, const char *postfix)
 {
        int len1 = strlen(string), len2 = strlen(postfix);
@@ -46,6 +48,7 @@ static int opt_parse_track(const struct option *opt, const char *arg, int not)
 static int fetch_remote(const char *name)
 {
        const char *argv[] = { "fetch", name, NULL };
+       printf("Updating %s\n", name);
        if (run_command_v_opt(argv, RUN_GIT_CMD))
                return error("Could not fetch %s", name);
        return 0;
@@ -87,19 +90,24 @@ static int add(int argc, const char **argv)
        strbuf_init(&buf, 0);
        strbuf_init(&buf2, 0);
 
+       strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
+       if (!valid_fetch_refspec(buf2.buf))
+               die("'%s' is not a valid remote name", name);
+
        strbuf_addf(&buf, "remote.%s.url", name);
        if (git_config_set(buf.buf, url))
                return 1;
 
+       strbuf_reset(&buf);
+       strbuf_addf(&buf, "remote.%s.fetch", name);
+
        if (track.nr == 0)
                path_list_append("*", &track);
        for (i = 0; i < track.nr; i++) {
                struct path_list_item *item = track.items + i;
 
-               strbuf_reset(&buf);
-               strbuf_addf(&buf, "remote.%s.fetch", name);
-
                strbuf_reset(&buf2);
+               strbuf_addch(&buf2, '+');
                if (mirror)
                        strbuf_addf(&buf2, "refs/%s:refs/%s",
                                        item->path, item->path);
@@ -110,6 +118,13 @@ static int add(int argc, const char **argv)
                        return 1;
        }
 
+       if (mirror) {
+               strbuf_reset(&buf);
+               strbuf_addf(&buf, "remote.%s.mirror", name);
+               if (git_config_set(buf.buf, "yes"))
+                       return 1;
+       }
+
        if (fetch && fetch_remote(name))
                return 1;
 
@@ -206,7 +221,10 @@ static int handle_one_branch(const char *refname,
        if (!remote_find_tracking(states->remote, &refspec)) {
                struct path_list_item *item;
                const char *name = skip_prefix(refspec.src, "refs/heads/");
-               if (unsorted_path_list_has_path(&states->tracked, name) ||
+               /* symbolic refs pointing nowhere were handled already */
+               if ((flags & REF_ISSYMREF) ||
+                               unsorted_path_list_has_path(&states->tracked,
+                                       name) ||
                                unsorted_path_list_has_path(&states->new,
                                        name))
                        return 0;
@@ -264,6 +282,11 @@ static int add_branch_for_removal(const char *refname,
 
        if (!prefixcmp(refname, branches->prefix)) {
                struct path_list_item *item;
+
+               /* make sure that symrefs are deleted */
+               if (flags & REF_ISSYMREF)
+                       return unlink(git_path(refname));
+
                item = path_list_append(refname, branches->branches);
                item->util = xmalloc(20);
                hashcpy(item->util, sha1);
@@ -371,8 +394,11 @@ static int show_or_prune(int argc, const char **argv, int prune)
 
        argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 
-       if (argc < 1)
+       if (argc < 1) {
+               if (!prune)
+                       return show_all();
                usage_with_options(builtin_remote_usage, options);
+       }
 
        memset(&states, 0, sizeof(states));
        for (; argc; argc--, argv++) {
@@ -463,6 +489,7 @@ static int show_or_prune(int argc, const char **argv, int prune)
                                        spec->dst ? ":" : "",
                                        skip_prefix(spec->dst, "refs/heads/"));
                        }
+                       printf("\n");
                }
 cleanup_states:
                /* NEEDSWORK: free remote */