[PATCH] git-remote: make remote name optional for prune operation
If `git remote prune` is called without a name, prune all remotes.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
Documentation/git-remote.txt | 4 +++-
builtin-remote.c | 26 +++++++++++++++++++++-----
t/t5505-remote.sh | 21 +++++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 9e2b4ea..5c8477e 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -15,7 +15,7 @@ SYNOPSIS
'git remote rm' <name>
'git remote set-head' <name> [-a | -d | <branch>]
'git remote show' [-n] <name>
-'git remote prune' [-n | --dry-run] <name>
+'git remote prune' [-n | --dry-run] [name]
'git remote update' [-p | --prune] [group | remote]...
DESCRIPTION
@@ -116,6 +116,8 @@ referenced by <name>, but are still locally available in
+
With `--dry-run` option, report what branches will be pruned, but do no
actually prune them.
+If <name> is not set, all stale branches from all remote repositories will
+be deleted.
'update'::
diff --git a/builtin-remote.c b/builtin-remote.c
index 2ed752c..053d886 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -14,7 +14,7 @@ static const char * const builtin_remote_usage[] = {
"git remote rm <name>",
"git remote set-head <name> [-a | -d | <branch>]",
"git remote show [-n] <name>",
- "git remote prune [-n | --dry-run] <name>",
+ "git remote prune [-n | --dry-run] [name]",
"git remote [-v | --verbose] update [-p | --prune] [group]",
NULL
};
@@ -25,6 +25,7 @@ static const char * const builtin_remote_usage[] = {
static int verbose;
+static int get_one_entry(struct remote *remote, void *priv);
static int show_all(void);
static int prune_remote(const char *remote, int dry_run);
@@ -1133,10 +1134,25 @@ static int prune(int argc, const char **argv)
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
if (argc < 1)
- usage_with_options(builtin_remote_usage, options);
+ {
+ struct string_list list = { NULL, 0, 0 };
+ int result = for_each_remote(get_one_entry, &list);
+
+ if (!result) {
+ int i;
- for (; argc; argc--, argv++)
- result |= prune_remote(*argv, dry_run);
+ sort_string_list(&list);
+ for (i = 0; i < list.nr; i++) {
+ struct string_list_item *item = list.items + i;
+ if (i && !strcmp((item - 1)->string, item->string))
+ continue;
+ result |= prune_remote(item->string, dry_run);
+ }
+ }
+ }
+ else
+ for (; argc; argc--, argv++)
+ result |= prune_remote(*argv, dry_run);
return result;
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 5ec668d..cfb7922 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -223,6 +223,27 @@ test_expect_success 'prune' '
test_must_fail git rev-parse refs/remotes/origin/side)
'
+test_expect_success 'prune-all' '
+ (cd one &&
+ git branch side3 side2) &&
+ (cd test &&
+ git fetch origin) &&
+ (cd one &&
+ git branch -D side3) &&
+ (cd two &&
+ git branch side2 side) &&
+ (cd test &&
+ git fetch two) &&
+ (cd two &&
+ git branch -D side2) &&
+ (cd test &&
+ git fetch origin &&
+ git fetch two &&
+ git remote prune &&
+ test_must_fail git rev-parse refs/remotes/origin/side3 &&
+ test_must_fail git rev-parse refs/remotes/two/side2)
+'
+
test_expect_success 'set-head --delete' '
(cd test &&
git symbolic-ref refs/remotes/origin/HEAD &&
--
1.6.2.4