git remote update: New option --prune
With the --prune (or -p) option, git remote update will also prune all the remotes that it fetches. Previously, you had to do a manual git remote prune <remote> for each of the remotes you wanted to prune, and this could be tedious with many remotes. A single command will now update a set of remotes, and remove all stale branches: git remote update -p [group] Signed-off-by: Finn Arne Gangstad <finnag@pvv.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Finn Arne Gangstad committed
Apr 3, 2009 at 11:03 UTC
efa54803cb1dc15923799f94abf82cb0433c2b9b
2 files changed
+19
-5
Documentation/git-remote.txt
+3
-1
@@ -16,7 +16,7 @@ SYNOPSIS
16
'git remote set-head' <name> [-a | -d | <branch>]
17
'git remote show' [-n] <name>
18
'git remote prune' [-n | --dry-run] <name>
19
-'git remote update' [group]
19
+'git remote update' [-p | --prune] [group]
20
21
DESCRIPTION
22
-----------
@@ -125,6 +125,8 @@ the configuration parameter remotes.default will get used; if
125
remotes.default is not defined, all remotes which do not have the
126
configuration parameter remote.<name>.skipDefaultUpdate set to true will
127
be updated. (See linkgit:git-config[1]).
128
++
129
+With `--prune` option, prune all the remotes that are updated.
130
131
132
DISCUSSION
builtin-remote.c
+16
-4
@@ -15,7 +15,7 @@ static const char * const builtin_remote_usage[] = {
15
"git remote set-head <name> [-a | -d | <branch>]",
16
"git remote show [-n] <name>",
17
"git remote prune [-n | --dry-run] <name>",
18
- "git remote [-v | --verbose] update [group]",
18
+ "git remote [-v | --verbose] update [-p | --prune] [group]",
19
NULL
20
};
21
@@ -1208,10 +1208,18 @@ static int get_remote_group(const char *key, const char *value, void *cb)
1208
1209
static int update(int argc, const char **argv)
1210
{
1211
- int i, result = 0;
1211
+ int i, result = 0, prune = 0;
1212
struct string_list list = { NULL, 0, 0, 0 };
1213
static const char *default_argv[] = { NULL, "default", NULL };
1214
+ struct option options[] = {
1215
+ OPT_GROUP("update specific options"),
1216
+ OPT_BOOLEAN('p', "prune", &prune,
1217
+ "prune remotes after fecthing"),
1218
+ OPT_END()
1219
+ };
1220
1221
+ argc = parse_options(argc, argv, options, builtin_remote_usage,
1222
+ PARSE_OPT_KEEP_ARGV0);
1223
if (argc < 2) {
1224
argc = 2;
1225
argv = default_argv;
@@ -1226,8 +1234,12 @@ static int update(int argc, const char **argv)
1234
if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default"))
1235
result = for_each_remote(get_one_remote_for_update, &list);
1236
1229
- for (i = 0; i < list.nr; i++)
1230
- result |= fetch_remote(list.items[i].string);
1237
+ for (i = 0; i < list.nr; i++) {
1238
+ int err = fetch_remote(list.items[i].string);
1239
+ result |= err;
1240
+ if (!err && prune)
1241
+ result |= prune_remote(list.items[i].string, 0);
1242
+ }
1243
1244
/* all names were strdup()ed or strndup()ed */
1245
list.strdup_strings = 1;