]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-remote.c
Extend parse-options test suite
[git.git] / builtin-remote.c
index 745a4ee6c503666bf763327d845c4210a728261f..145dd8568c7a644344d8bb25ba395b10c5835c5c 100644 (file)
@@ -444,6 +444,22 @@ static int get_remote_ref_states(const char *name,
        return 0;
 }
 
+static int append_ref_to_tracked_list(const char *refname,
+       const unsigned char *sha1, int flags, void *cb_data)
+{
+       struct ref_states *states = cb_data;
+       struct refspec refspec;
+
+       memset(&refspec, 0, sizeof(refspec));
+       refspec.dst = (char *)refname;
+       if (!remote_find_tracking(states->remote, &refspec)) {
+               path_list_append(skip_prefix(refspec.src, "refs/heads/"),
+                       &states->tracked);
+       }
+
+       return 0;
+}
+
 static int show(int argc, const char **argv)
 {
        int no_query = 0, result = 0;
@@ -494,10 +510,12 @@ static int show(int argc, const char **argv)
                        strbuf_release(&buf);
                        show_list("  Stale tracking branch%s (use 'git remote "
                                "prune')", &states.stale);
-                       show_list("  Tracked remote branch%s",
-                               &states.tracked);
                }
 
+               if (no_query)
+                       for_each_ref(append_ref_to_tracked_list, &states);
+               show_list("  Tracked remote branch%s", &states.tracked);
+
                if (states.remote->push_refspec_nr) {
                        printf("  Local branch%s pushed with 'git push'\n   ",
                                states.remote->push_refspec_nr > 1 ?
@@ -523,10 +541,10 @@ static int show(int argc, const char **argv)
 
 static int prune(int argc, const char **argv)
 {
-       int no_query = 0, result = 0;
+       int dry_run = 0, result = 0;
        struct option options[] = {
                OPT_GROUP("prune specific options"),
-               OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
+               OPT__DRY_RUN(&dry_run),
                OPT_END()
        };
        struct ref_states states;
@@ -540,11 +558,24 @@ static int prune(int argc, const char **argv)
        for (; argc; argc--, argv++) {
                int i;
 
-               get_remote_ref_states(*argv, &states, !no_query);
+               get_remote_ref_states(*argv, &states, 1);
+
+               if (states.stale.nr) {
+                       printf("Pruning %s\n", *argv);
+                       printf("URL: %s\n",
+                              states.remote->url_nr
+                              ? states.remote->url[0]
+                              : "(no URL)");
+               }
 
                for (i = 0; i < states.stale.nr; i++) {
                        const char *refname = states.stale.items[i].util;
-                       result |= delete_ref(refname, NULL);
+
+                       if (!dry_run)
+                               result |= delete_ref(refname, NULL);
+
+                       printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
+                              skip_prefix(refname, "refs/remotes/"));
                }
 
                /* NEEDSWORK: free remote */