@matheusbsbs / matheus-bagliano / commits / 8d7679276a
Fork 0

remote prune: print the list of pruned branches

This command is really too quiet which make it unconfortable to use. Also implement a --dry-run option, in place of the original -n one, to list stale tracking branches that will be pruned, but do not actually prune them. Add a test case for --dry-run. Signed-off-by: Olivier Marin <dkr@freesurf.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Olivier Marin committed Jun 10, 2008 at 16:51 UTC 8d7679276af861b44e307c9879f6c4774f4944fc
3 files changed +37 -8
Documentation/git-remote.txt
+3 -4
@@ -13,7 +13,7 @@ SYNOPSIS
13 'git-remote' add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
14 'git-remote' rm <name>
15 'git-remote' show [-n] <name>
16 -'git-remote' prune <name>
16 +'git-remote' prune [-n | --dry-run] <name>
17 'git-remote' update [group]
18
19 DESCRIPTION
@@ -80,9 +80,8 @@ These stale branches have already been removed from the remote repository
80 referenced by <name>, but are still locally available in
81 "remotes/<name>".
82 +
83 -With `-n` option, the remote heads are not confirmed first with `git
84 -ls-remote <name>`; cached information is used instead. Use with
85 -caution.
83 +With `--dry-run` option, report what branches will be pruned, but do no
84 +actually prune them.
85
86 'update'::
87
builtin-remote.c
+16 -4
@@ -523,10 +523,10 @@ static int show(int argc, const char **argv)
523
524 static int prune(int argc, const char **argv)
525 {
526 - int no_query = 0, result = 0;
526 + int dry_run = 0, result = 0;
527 struct option options[] = {
528 OPT_GROUP("prune specific options"),
529 - OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
529 + OPT__DRY_RUN(&dry_run),
530 OPT_END()
531 };
532 struct ref_states states;
@@ -540,11 +540,23 @@ static int prune(int argc, const char **argv)
540 for (; argc; argc--, argv++) {
541 int i;
542
543 - get_remote_ref_states(*argv, &states, !no_query);
543 + get_remote_ref_states(*argv, &states, 1);
544 +
545 + printf("Pruning %s\n", *argv);
546 + if (states.stale.nr)
547 + printf("URL: %s\n",
548 + states.remote->url_nr
549 + ? states.remote->url[0]
550 + : "(no URL)");
551
552 for (i = 0; i < states.stale.nr; i++) {
553 const char *refname = states.stale.items[i].util;
547 - result |= delete_ref(refname, NULL);
554 +
555 + if (!dry_run)
556 + result |= delete_ref(refname, NULL);
557 +
558 + printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
559 + skip_prefix(refname, "refs/remotes/"));
560 }
561
562 /* NEEDSWORK: free remote */
t/t5505-remote.sh
+18
@@ -165,6 +165,24 @@ test_expect_success 'prune' '
165 ! git rev-parse refs/remotes/origin/side)
166 '
167
168 +cat > test/expect << EOF
169 +Pruning origin
170 +URL: $(pwd)/one/.git
171 + * [would prune] origin/side2
172 +EOF
173 +
174 +test_expect_success 'prune --dry-run' '
175 + (cd one &&
176 + git branch -m side2 side) &&
177 + (cd test &&
178 + git remote prune --dry-run origin > output &&
179 + git rev-parse refs/remotes/origin/side2 &&
180 + ! git rev-parse refs/remotes/origin/side &&
181 + (cd ../one &&
182 + git branch -m side side2) &&
183 + test_cmp expect output)
184 +'
185 +
186 test_expect_success 'add --mirror && prune' '
187 (mkdir mirror &&
188 cd mirror &&