]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-remote.c
replace direct calls to unlink(2) with unlink_or_warn
[git.git] / builtin-remote.c
index c53966fd8d565f8328f9dd9c7146607d65ff7ae9..71abf68404f5b260ba96208717d89e50e778dd36 100644 (file)
@@ -15,7 +15,7 @@ static const char * const builtin_remote_usage[] = {
        "git remote set-head <name> [-a | -d | <branch>]",
        "git remote show [-n] <name>",
        "git remote prune [-n | --dry-run] <name>",
-       "git remote [-v | --verbose] update [group]",
+       "git remote [-v | --verbose] update [-p | --prune] [group]",
        NULL
 };
 
@@ -525,8 +525,8 @@ static int migrate_file(struct remote *remote)
                path = git_path("remotes/%s", remote->name);
        else if (remote->origin == REMOTE_BRANCHES)
                path = git_path("branches/%s", remote->name);
-       if (path && unlink(path))
-               warning("failed to remove '%s'", path);
+       if (path)
+               unlink_or_warn(path);
        return 0;
 }
 
@@ -1188,16 +1188,18 @@ struct remote_group {
        struct string_list *list;
 } remote_group;
 
-static int get_remote_group(const char *key, const char *value, void *cb)
+static int get_remote_group(const char *key, const char *value, void *num_hits)
 {
        if (!prefixcmp(key, "remotes.") &&
                        !strcmp(key + 8, remote_group.name)) {
                /* split list by white space */
                int space = strcspn(value, " \t\n");
                while (*value) {
-                       if (space > 1)
+                       if (space > 1) {
                                string_list_append(xstrndup(value, space),
                                                remote_group.list);
+                               ++*((int *)num_hits);
+                       }
                        value += space + (value[space] != '\0');
                        space = strcspn(value, " \t\n");
                }
@@ -1208,10 +1210,18 @@ static int get_remote_group(const char *key, const char *value, void *cb)
 
 static int update(int argc, const char **argv)
 {
-       int i, result = 0;
+       int i, result = 0, prune = 0;
        struct string_list list = { NULL, 0, 0, 0 };
        static const char *default_argv[] = { NULL, "default", NULL };
+       struct option options[] = {
+               OPT_GROUP("update specific options"),
+               OPT_BOOLEAN('p', "prune", &prune,
+                           "prune remotes after fetching"),
+               OPT_END()
+       };
 
+       argc = parse_options(argc, argv, options, builtin_remote_usage,
+                            PARSE_OPT_KEEP_ARGV0);
        if (argc < 2) {
                argc = 2;
                argv = default_argv;
@@ -1219,15 +1229,28 @@ static int update(int argc, const char **argv)
 
        remote_group.list = &list;
        for (i = 1; i < argc; i++) {
+               int groups_found = 0;
                remote_group.name = argv[i];
-               result = git_config(get_remote_group, NULL);
+               result = git_config(get_remote_group, &groups_found);
+               if (!groups_found && (i != 1 || strcmp(argv[1], "default"))) {
+                       struct remote *remote;
+                       if (!remote_is_configured(argv[i]))
+                               die("No such remote or remote group: %s",
+                                   argv[i]);
+                       remote = remote_get(argv[i]);
+                       string_list_append(remote->name, remote_group.list);
+               }
        }
 
        if (!result && !list.nr  && argc == 2 && !strcmp(argv[1], "default"))
                result = for_each_remote(get_one_remote_for_update, &list);
 
-       for (i = 0; i < list.nr; i++)
-               result |= fetch_remote(list.items[i].string);
+       for (i = 0; i < list.nr; i++) {
+               int err = fetch_remote(list.items[i].string);
+               result |= err;
+               if (!err && prune)
+                       result |= prune_remote(list.items[i].string, 0);
+       }
 
        /* all names were strdup()ed or strndup()ed */
        list.strdup_strings = 1;