From c0192df6306d4d9ad77f6015a053925b13155834 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Wed, 30 Sep 2020 14:25:29 -0700 Subject: refspec: add support for negative refspecs Both fetch and push support pattern refspecs which allow fetching or pushing references that match a specific pattern. Because these patterns are globs, they have somewhat limited ability to express more complex situations. For example, suppose you wish to fetch all branches from a remote except for a specific one. To allow this, you must setup a set of refspecs which match only the branches you want. Because refspecs are either explicit name matches, or simple globs, many patterns cannot be expressed. Add support for a new type of refspec, referred to as "negative" refspecs. These are prefixed with a '^' and mean "exclude any ref matching this refspec". They can only have one "side" which always refers to the source. During a fetch, this refers to the name of the ref on the remote. During a push, this refers to the name of the ref on the local side. With negative refspecs, users can express more complex patterns. For example: git fetch origin refs/heads/*:refs/remotes/origin/* ^refs/heads/dontwant will fetch all branches on origin into remotes/origin, but will exclude fetching the branch named dontwant. Refspecs today are commutative, meaning that order doesn't expressly matter. Rather than forcing an implied order, negative refspecs will always be applied last. That is, in order to match, a ref must match at least one positive refspec, and match none of the negative refspecs. This is similar to how negative pathspecs work. Signed-off-by: Jacob Keller Signed-off-by: Junio C Hamano --- Documentation/pull-fetch-param.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Documentation') diff --git a/Documentation/pull-fetch-param.txt b/Documentation/pull-fetch-param.txt index 95ea849902..95a7390b2c 100644 --- a/Documentation/pull-fetch-param.txt +++ b/Documentation/pull-fetch-param.txt @@ -30,6 +30,22 @@ The colon can be omitted when is empty. is typically a ref, but it can also be a fully spelled hex object name. + +A may contain a `*` in its to indicate a simple pattern +match. Such a refspec functions like a glob that matches any ref with the +same prefix. A pattern must have a `*` in both the and +. It will map refs to the destination by replacing the `*` with the +contents matched from the source. ++ +If a refspec is prefixed by `^`, it will be interpreted as a negative +refspec. Rather than specifying which refs to fetch or which local refs to +update, such a refspec will instead specify refs to exclude. A ref will be +considered to match if it matches at least one positive refspec, and does +not match any negative refspec. Negative refspecs can be useful to restrict +the scope of a pattern refspec so that it will not include specific refs. +Negative refspecs can themselves be pattern refspecs. However, they may only +contain a and do not specify a . Fully spelled out hex object +names are also not supported. ++ `tag ` means the same as `refs/tags/:refs/tags/`; it requests fetching everything up to the given tag. + -- cgit v1.2.3