Re: [PATCH v3 11/11] fetch: add a --fetch-prune option and fetch.pruneTags config

2018-01-24 Thread Junio C Hamano
Ævar Arnfjörð Bjarmason  writes:

> On Wed, Jan 24 2018, Junio C. Hamano jotted:
>
>> Ævar Arnfjörð Bjarmason   writes:
>>
>>>  git -C {} config --replace-all remote.origin.fetch 
>>> "+refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"
>>
>> Shouldn't the last arg be
>>
>>  '^+\*refs/tags/\*:refs/tags/\*$'
>>
>> instead?
>
> ^+\* isn't a valid pattern.

Yikes, sorry for the noise.  You did mean "there might be a plus
sign at the beginning, but there may not be".



Re: [PATCH v3 11/11] fetch: add a --fetch-prune option and fetch.pruneTags config

2018-01-24 Thread Ævar Arnfjörð Bjarmason

On Wed, Jan 24 2018, Junio C. Hamano jotted:

> Ævar Arnfjörð Bjarmason   writes:
>
>>  git -C {} config --replace-all remote.origin.fetch 
>> "+refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"
>
> Shouldn't the last arg be
>
>  '^+\*refs/tags/\*:refs/tags/\*$'
>
> instead?

^+\* isn't a valid pattern.

This invocation is to replace both +refs/tags/[...] and refs/tags/[...]
with +refs/tags/[...]. This would be more specific, i.e. ^\+?

 git config --replace-all remote.origin.fetch "+refs/tags/*:refs/tags/*" 
"^\+?refs/tags/\*:refs/tags/\*$"

But I couldn't remeber offhand whether all regcomp() we use supports X?,
whereas they definitely do support X*.


Re: [PATCH v3 11/11] fetch: add a --fetch-prune option and fetch.pruneTags config

2018-01-24 Thread Junio C Hamano
Ævar Arnfjörð Bjarmason   writes:

>  git -C {} config --replace-all remote.origin.fetch 
> "+refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"

Shouldn't the last arg be

 '^+\*refs/tags/\*:refs/tags/\*$'

instead?


[PATCH v3 11/11] fetch: add a --fetch-prune option and fetch.pruneTags config

2018-01-23 Thread Ævar Arnfjörð Bjarmason
Add a --fetch-prune option to git-fetch, along with fetch.pruneTags
config option. This allows for doing any of:

git fetch -p -P
git fetch --prune --prune-tags
git fetch -p -P origin
git fetch --prune --prune-tags origin

Or simply:

git config fetch.prune true &&
git config fetch.pruneTags true &&
git fetch

Instead of the much more verbose:

git fetch --prune origin '+refs/tags/*:refs/tags/*' 
'+refs/heads/*:refs/remotes/origin/*'

Before this feature it was painful to support the use-case of pulling
from a repo which is having both its branches *and* tags deleted
regularly, and have our local references to reflect upstream.

At work we create deployment tags in the repo for each rollout, and
there's *lots* of those, so they're archived within weeks for
performance reasons.

Without this change it's hard to centrally configure such repos in
/etc/gitconfig (on servers that are only used for working with
them). You need to set fetch.prune=true globally, and then for each
repo:

git -C {} config --replace-all remote.origin.fetch 
"+refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"

Now I can simply set fetch.pruneTags=true in /etc/gitconfig as well,
and users running "git pull" will automatically get the pruning
semantics I want.

Even though "git remote" has corresponding "prune" and "update
--prune" subcommands I'm intentionally not adding a corresponding
prune-tags or "update --prune --prune-tags" mode to that command.

It's advertised (as noted in my recent "git remote doc: correct
dangerous lies about what prune does") as only modifying remote
tracking references, whereas any --prune-tags option is always going
to modify what from the user's perspective is a local copy of the tag,
since there's no such thing as a remote tracking tag.

See my "Re: [BUG] git remote prune removes local tags, depending on
fetch config" (87po6ahx87@evledraar.gmail.com;
https://public-inbox.org/git/87po6ahx87@evledraar.gmail.com/) for
more background info.

Signed-off-by: Ævar Arnfjörð Bjarmason 
---
 Documentation/config.txt   | 14 ++
 Documentation/fetch-options.txt| 15 ++-
 Documentation/git-fetch.txt| 27 +++
 builtin/fetch.c| 32 
 contrib/completion/git-completion.bash |  2 +-
 remote.c   |  5 -
 remote.h   |  3 +++
 t/t5510-fetch.sh   | 30 ++
 8 files changed, 125 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 0f27af5760..ae86455876 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1401,6 +1401,14 @@ fetch.prune::
option was given on the command line.  See also `remote..prune`
and the PRUNING section of linkgit:git-fetch[1].
 
+fetch.pruneTags::
+   If true, fetch will automatically behave as if the
+   `refs/tags/*:refs/tags/*` refspec was provided when pruning,
+   if not set already. This allows for setting both this option
+   and `fetch.prune` to maintain a 1=1 mapping to upstrem
+   refs. See also `remote..pruneTags` and the PRUNING
+   section of linkgit:git-fetch[1].
+
 fetch.output::
Control how ref update status is printed. Valid values are
`full` and `compact`. Default value is `full`. See section
@@ -2945,6 +2953,12 @@ remote..prune::
remove any remote-tracking references that no longer exist on the
remote (as if the `--prune` option was given on the command line).
Overrides `fetch.prune` settings, if any.
+
+remote..pruneTags::
+   When set to true, fetching from this remote by default will also
+   remove any local tags that no longer exist on the remote if pruning
+   is activated in general via `remote..prune`, `fetch.prune` or
+   `--prune`. Overrides `fetch.pruneTags` settings, if any.
 +
 See also `remote..prune` and the PRUNING section of
 linkgit:git-fetch[1].
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 9f5c85ad96..dc13bed741 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -73,7 +73,20 @@ ifndef::git-pull[]
are fetched due to an explicit refspec (either on the command
line or in the remote configuration, for example if the remote
was cloned with the --mirror option), then they are also
-   subject to pruning.
+   subject to pruning. Supplying `--prune-tags` is a shorthand for
+   providing the tag refspec.
++
+See the PRUNING section below for more details.
+
+-P::
+--prune-tags::
+   Before fetching, remove any local tags that no longer exist on
+   the remote if `--prune` is enabled. This option should be used
+   more carefully, unlike `--prune` it will remove any local
+   references