git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Julien Danjou <julien@danjou.info>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Julien Danjou <julien@danjou.info>
Subject: [PATCH] git-remote: make remote name optional for prune operation
Date: Wed,  6 May 2009 18:58:01 +0200	[thread overview]
Message-ID: <1241629081-11122-1-git-send-email-julien@danjou.info> (raw)
In-Reply-To: <4A01B7A7.9020308@drmicha.warpmail.net>

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

  reply	other threads:[~2009-05-06 16:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-06 14:37 [PATCH] git-remote: make remote name optional for prune operation Julien Danjou
2009-05-06 14:49 ` Francis Galiegue
2009-05-06 15:32   ` Julien Danjou
2009-05-06 15:46     ` Jacob Helwig
2009-05-06 16:15       ` Michael J Gruber
2009-05-06 16:58         ` Julien Danjou [this message]
2009-05-06 17:18 ` Junio C Hamano
2009-05-06 17:54   ` Junio C Hamano
2009-05-06 17:55   ` Finn Arne Gangstad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1241629081-11122-1-git-send-email-julien@danjou.info \
    --to=julien@danjou.info \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).