From: Erik Faye-Lund Date: Mon, 03 Oct 2011 12:16:08 GMT Subject: [PATCH/RFC] remote: support --all for the prune-subcommand Message-ID: <1317644168-5808-1-git-send-email-kusmabite@gmail.com> While we're at it, wrap a long line to fit on a 80 char terminal. Signed-off-by: Erik Faye-Lund --- I recently needed to prune remote branches in a repo with a lot of remotes, and to my surprise "git remote prune" didn't support the --all option. So I added it. Perhaps this is useful for other people as well? Documentation/git-remote.txt | 2 +- builtin/remote.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 5a8c506..856cc7f 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -19,7 +19,7 @@ SYNOPSIS 'git remote set-url --add' [--push] 'git remote set-url --delete' [--push] 'git remote' [-v | --verbose] 'show' [-n] -'git remote prune' [-n | --dry-run] +'git remote prune' [-n | --dry-run] (--all | ...) 'git remote' [-v | --verbose] 'update' [-p | --prune] [( | )...] DESCRIPTION diff --git a/builtin/remote.c b/builtin/remote.c index f2a9c26..2e8407d 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -14,7 +14,7 @@ static const char * const builtin_remote_usage[] = { "git remote rm ", "git remote set-head (-a | -d | )", "git remote [-v | --verbose] show [-n] ", - "git remote prune [-n | --dry-run] ", + "git remote prune [-n | --dry-run] (--all | )", "git remote [-v | --verbose] update [-p | --prune] [( | )...]", "git remote set-branches [--add] ...", "git remote set-url []", @@ -1222,22 +1222,35 @@ static int set_head(int argc, const char **argv) return result; } +static int add_one_remote(struct remote *remote, void *remotes) +{ + string_list_append(remotes, remote->name); + return 0; +} + static int prune(int argc, const char **argv) { - int dry_run = 0, result = 0; + struct string_list remotes = STRING_LIST_INIT_NODUP; + int dry_run = 0, result = 0, all = 0, i; struct option options[] = { + OPT_BOOLEAN(0, "all", &all, "prune all remotes"), OPT__DRY_RUN(&dry_run, "dry run"), OPT_END() }; - argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage, - 0); + argc = parse_options(argc, argv, NULL, options, + builtin_remote_prune_usage, 0); - if (argc < 1) + if (all) + for_each_remote(add_one_remote, &remotes); + else if (argc < 1) usage_with_options(builtin_remote_prune_usage, options); + else + for (; argc; argc--, argv++) + string_list_append(&remotes, *argv); - for (; argc; argc--, argv++) - result |= prune_remote(*argv, dry_run); + for (i = 0; i < remotes.nr; ++i) + result |= prune_remote(remotes.items[i].string, dry_run); return result; } -- 1.7.6.msysgit.0.579.ga3d6f