Skip to content

Commit efa5480

Browse files
Finn Arne Gangstadgitster
authored andcommitted
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>
1 parent b92c5f2 commit efa5480

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Documentation/git-remote.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SYNOPSIS
1616
'git remote set-head' <name> [-a | -d | <branch>]
1717
'git remote show' [-n] <name>
1818
'git remote prune' [-n | --dry-run] <name>
19-
'git remote update' [group]
19+
'git remote update' [-p | --prune] [group]
2020

2121
DESCRIPTION
2222
-----------
@@ -125,6 +125,8 @@ the configuration parameter remotes.default will get used; if
125125
remotes.default is not defined, all remotes which do not have the
126126
configuration parameter remote.<name>.skipDefaultUpdate set to true will
127127
be updated. (See linkgit:git-config[1]).
128+
+
129+
With `--prune` option, prune all the remotes that are updated.
128130

129131

130132
DISCUSSION

builtin-remote.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static const char * const builtin_remote_usage[] = {
1515
"git remote set-head <name> [-a | -d | <branch>]",
1616
"git remote show [-n] <name>",
1717
"git remote prune [-n | --dry-run] <name>",
18-
"git remote [-v | --verbose] update [group]",
18+
"git remote [-v | --verbose] update [-p | --prune] [group]",
1919
NULL
2020
};
2121

@@ -1208,10 +1208,18 @@ static int get_remote_group(const char *key, const char *value, void *cb)
12081208

12091209
static int update(int argc, const char **argv)
12101210
{
1211-
int i, result = 0;
1211+
int i, result = 0, prune = 0;
12121212
struct string_list list = { NULL, 0, 0, 0 };
12131213
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+
};
12141220

1221+
argc = parse_options(argc, argv, options, builtin_remote_usage,
1222+
PARSE_OPT_KEEP_ARGV0);
12151223
if (argc < 2) {
12161224
argc = 2;
12171225
argv = default_argv;
@@ -1226,8 +1234,12 @@ static int update(int argc, const char **argv)
12261234
if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default"))
12271235
result = for_each_remote(get_one_remote_for_update, &list);
12281236

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+
}
12311243

12321244
/* all names were strdup()ed or strndup()ed */
12331245
list.strdup_strings = 1;

0 commit comments

Comments
 (0)