# [PATCH] git-remote: make remote name optional for prune operation

9 messages from 2009-05-06 to 2009-05-06. Participants: Julien Danjou, Francis Galiegue, Jacob Helwig, Michael J Gruber, Junio C Hamano, Finn Arne Gangstad.
Thread: https://gitlist.dev/t/19197

## Julien Danjou, 2009-05-06 14:37

Subject: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <1241620621-12188-1-git-send-email-julien@danjou.info>
URL: https://gitlist.dev/e/1241620621-12188-1-git-send-email-julien%40danjou.info

```
We consider that if `git remote prune` is called without a name, we
actually want to prune all remotes.

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 Documentation/git-remote.txt |    2 +-
 builtin-remote.c             |   26 +++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 9e2b4ea..c566061 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
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;
 }
-- 
1.6.2.4

```

## Francis Galiegue, 2009-05-06 14:49

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <200905061649.25351.fge@one2team.com>
URL: https://gitlist.dev/e/200905061649.25351.fge%40one2team.com
In-Reply-To: <1241620621-12188-1-git-send-email-julien@danjou.info>

```
Le mercredi 06 mai 2009, Julien Danjou a écrit :

[...]

Didn't you forget a little something in your patch?

[...]
> diff --git a/builtin-remote.c b/builtin-remote.c
[...]
> @@ -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);
[...]
>  
>  	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);



-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

```

## Julien Danjou, 2009-05-06 15:32

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <20090506153212.GF10701@abydos.adm.naquadah.org>
URL: https://gitlist.dev/e/20090506153212.GF10701%40abydos.adm.naquadah.org
In-Reply-To: <200905061649.25351.fge@one2team.com>

```
At 1241621365 time_t, Francis Galiegue wrote:
> Didn't you forget a little something in your patch?

If so, I really can't see what.

Cheers,
-- 
Julien Danjou
// ᐰ <julien@danjou.info>   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// Tomorrow I was nothing, yesterday I'll be.

```

## Jacob Helwig, 2009-05-06 15:46

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <8c9a060905060846o1a7b26b0m78ff0cbe48648873@mail.gmail.com>
URL: https://gitlist.dev/e/8c9a060905060846o1a7b26b0m78ff0cbe48648873%40mail.gmail.com
In-Reply-To: <20090506153212.GF10701@abydos.adm.naquadah.org>

```
On Wed, May 6, 2009 at 08:32, Julien Danjou <julien@danjou.info> wrote:
> At 1241621365 time_t, Francis Galiegue wrote:
>> Didn't you forget a little something in your patch?
>
> If so, I really can't see what.
>
> Cheers,
> --
> Julien Danjou
> // ᐰ <julien@danjou.info>   http://julien.danjou.info
> // 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
> // Tomorrow I was nothing, yesterday I'll be.
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkoBrXoACgkQpGK1HsL+5c1TdwCgltFTU6aZmLUWzXFzNkq7Dqo5
> FywAoJTEUtDJO2LrzQyu+jB0vf9XCbe2
> =pF1M
> -----END PGP SIGNATURE-----
>
>

I'm guessing, but perhaps Francis means a test for this behavior?

```

## Michael J Gruber, 2009-05-06 16:15

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <4A01B7A7.9020308@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4A01B7A7.9020308%40drmicha.warpmail.net
In-Reply-To: <8c9a060905060846o1a7b26b0m78ff0cbe48648873@mail.gmail.com>

```
Jacob Helwig venit, vidit, dixit 06.05.2009 17:46:
> On Wed, May 6, 2009 at 08:32, Julien Danjou <julien@danjou.info> wrote:
>> At 1241621365 time_t, Francis Galiegue wrote:
>>> Didn't you forget a little something in your patch?
>>
>> If so, I really can't see what.
>>
>> Cheers,
>> --
>> Julien Danjou
> 
> I'm guessing, but perhaps Francis means a test for this behavior?

Documentation (besides changing <> to []), test.
Also, it looks as if a get_one_entry() declaration is added without a
definition. But the definition is there already.

Michael

```

## Julien Danjou, 2009-05-06 16:58

Subject: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <1241629081-11122-1-git-send-email-julien@danjou.info>
URL: https://gitlist.dev/e/1241629081-11122-1-git-send-email-julien%40danjou.info
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

```

## Junio C Hamano, 2009-05-06 17:18

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <7vab5qw3nr.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vab5qw3nr.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1241620621-12188-1-git-send-email-julien@danjou.info>

```
Julien Danjou <julien@danjou.info> writes:

> We consider that if `git remote prune` is called without a name, we
> actually want to prune all remotes.

I think we try to make an opearation that discards information from many
things at once by mistake, and it feels that this patch goes against it.

In what situation does this new short-cut make things convenient, and how
often does such a situation come up?  The only one I can think of is when
you are interacting with many volatile remotes that create and delete
branches all the time, and when you are trying to repack/pack-ref your
local repository with as much cruft removed, but in such a set-up, next
time you interact with your remotes, you will get their "branch of the
day" in your remote tracking namespace that will disappear shortly, and it
does not sound like it is such a big deal if you did not run "remote
prune" to all of them at once anyway.

Having said all that...

> diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
> index 9e2b4ea..c566061 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]...

I think you would want to say [<name>] here, but looking at this list, I
wonder if it would be more appropriate to allow "remote group" to be given
to "prune" (and perhaps "show").

```

## Junio C Hamano, 2009-05-06 17:54

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <7vr5z2ungj.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr5z2ungj.fsf%40alter.siamese.dyndns.org
In-Reply-To: <7vab5qw3nr.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> I think we try to make an opearation that discards information from many
> things at once by mistake, and it feels that this patch goes against it.

Sorry, "by mistake" should have read "harder to trigger by mistake".

```

## Finn Arne Gangstad, 2009-05-06 17:55

Subject: Re: [PATCH] git-remote: make remote name optional for prune operation
Message-ID: <20090506175500.GA19976@pvv.org>
URL: https://gitlist.dev/e/20090506175500.GA19976%40pvv.org
In-Reply-To: <7vab5qw3nr.fsf@alter.siamese.dyndns.org>

```
On Wed, May 06, 2009 at 10:18:48AM -0700, Junio C Hamano wrote:
> Julien Danjou <julien@danjou.info> writes:
> 
> > We consider that if `git remote prune` is called without a name, we
> > actually want to prune all remotes.
> 
> I think we try to make an opearation that discards information from many
> things at once by mistake, and it feels that this patch goes against it.
> 
> In what situation does this new short-cut make things convenient, and how
> often does such a situation come up?  The only one I can think of is when
> you are interacting with many volatile remotes that create and delete
> branches all the time, and when you are trying to repack/pack-ref your
> local repository with as much cruft removed, but in such a set-up, next
> time you interact with your remotes, you will get their "branch of the
> day" in your remote tracking namespace that will disappear shortly, and it
> does not sound like it is such a big deal if you did not run "remote
> prune" to all of them at once anyway.
> 
> Having said all that...
> 
> > diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
> > index 9e2b4ea..c566061 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]...
> 
> I think you would want to say [<name>] here, but looking at this list, I
> wonder if it would be more appropriate to allow "remote group" to be given
> to "prune" (and perhaps "show").

I also think that if we want to change prune, we should change it to
interpret its parameters identically to update. This means that no
argument will not expand to "all remotes", but rather to the possibly
configured "default" group.

In other words: I think "git remote update -p" and "git remote prune"
should prune the same remotes (both with and without additional arguments).

- Finn Arne

```
