Allow optional arguments to be passed to "git fetch --prune" to choose which references are subject to pruning. The default, if no argument is specified, is to prune all references as before. Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> --- Documentation/fetch-options.txt | 6 +++++- builtin/fetch.c | 8 ++++++-- t/t5510-fetch.sh | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index f0ef7d0..61d3f75 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -40,7 +40,7 @@ ifndef::git-pull[] specified. No <refspec>s may be specified. -p:: ---prune:: +--prune[=<pattern>]:: After fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag @@ -49,6 +49,10 @@ ifndef::git-pull[] line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning. ++ +If pattern is specified, then it should be a glob pattern, and pruning +is further restricted to references whose names match the pattern. +This option can be specified multiple times. endif::git-pull[] ifndef::git-pull[] diff --git a/builtin/fetch.c b/builtin/fetch.c index fcc06a4..2cb48a6 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -73,9 +73,12 @@ static struct option builtin_fetch_options[] = { N_("fetch all tags and associated objects"), TAGS_SET), OPT_SET_INT('n', NULL, &tags, N_("do not fetch all tags (--no-tags)"), TAGS_UNSET), - { OPTION_CALLBACK, 'p', "prune", &prune_option, N_("pattern"), + { OPTION_CALLBACK, 'p', NULL, &prune_option, NULL, N_("prune remote-tracking branches no longer on remote"), PARSE_OPT_NOARG, prune_option_parse }, + { OPTION_CALLBACK, 0, "prune", &prune_option, N_("pattern"), + N_("prune remote-tracking branches (matching pattern, if specified)"), + PARSE_OPT_OPTARG, prune_option_parse }, { OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"), N_("control recursive fetching of submodules"), PARSE_OPT_OPTARG, option_parse_recurse_submodules }, @@ -702,7 +705,8 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map) static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map) { int result = 0; - struct ref *stale_refs = get_stale_heads(refs, ref_count, ref_map, NULL); + struct ref *stale_refs = get_stale_heads(refs, ref_count, ref_map, + &prune_option.prune_patterns); struct ref *ref; const char *dangling_msg = dry_run ? _(" (%s will become dangling)") diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 5d4581d..42eb21f 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -94,6 +94,18 @@ test_expect_success 'fetch --prune on its own works as expected' ' test_must_fail git rev-parse origin/extrabranch ' +test_expect_success 'fetch --prune with arguments' ' + cd "$D" && + git clone . prune-args && + cd prune-args && + git update-ref refs/remotes/origin/branch1 master && + git update-ref refs/remotes/origin/branch2 master && + + git fetch --prune="refs/remotes/origin/*1" origin && + test_must_fail git rev-parse origin/branch1 && + git rev-parse origin/branch2 +' + test_expect_success 'fetch --prune with a branch name keeps branches' ' cd "$D" && git clone . prune-branch && -- 1.8.4.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html