{"thread":{"id":"54331","subject":"[v4] refspec: add support for negative refspecs","startedAt":"2020-09-30T21:26:37Z","lastAt":"2020-09-30T22:01:31Z","messageCount":5,"participants":["Jacob Keller","Eric Sunshine","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"406714","messageId":"20200930212529.100458-1-jacob.e.keller@intel.com","threadId":"54331","inReplyTo":null,"subject":"[v4] refspec: add support for negative refspecs","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-09-30T21:25:29Z","receivedAt":"2020-09-30T21:26:37Z","isPatch":false,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nBoth fetch and push support pattern refspecs which allow fetching or\npushing references that match a specific pattern. Because these patterns\nare globs, they have somewhat limited ability to express more complex\nsituations.\n\nFor example, suppose you wish to fetch all branches from a remote except\nfor a specific one. To allow this, you must setup a set of refspecs\nwhich match only the branches you want. Because refspecs are either\nexplicit name matches, or simple globs, many patterns cannot be\nexpressed.\n\nAdd support for a new type of refspec, referred to as \"negative\"\nrefspecs. These are prefixed with a '^' and mean \"exclude any ref\nmatching this refspec\". They can only have one \"side\" which always\nrefers to the source. During a fetch, this refers to the name of the ref\non the remote. During a push, this refers to the name of the ref on the\nlocal side.\n\nWith negative refspecs, users can express more complex patterns. For\nexample:\n\n git fetch origin refs/heads/*:refs/remotes/origin/* ^refs/heads/dontwant\n\nwill fetch all branches on origin into remotes/origin, but will exclude\nfetching the branch named dontwant.\n\nRefspecs today are commutative, meaning that order doesn't expressly\nmatter. Rather than forcing an implied order, negative refspecs will\nalways be applied last. That is, in order to match, a ref must match at\nleast one positive refspec, and match none of the negative refspecs.\nThis is similar to how negative pathspecs work.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n\nChanges since v3\n* removed the ?: usage (for real this time)\n\n Documentation/pull-fetch-param.txt |  16 +++\n builtin/fetch.c                    |  10 ++\n refspec.c                          |  34 +++++-\n refspec.h                          |  14 ++-\n remote.c                           | 108 ++++++++++++++++-\n remote.h                           |   9 +-\n t/t5582-fetch-negative-refspec.sh  | 189 +++++++++++++++++++++++++++++\n 7 files changed, 367 insertions(+), 13 deletions(-)\n create mode 100755 t/t5582-fetch-negative-refspec.sh\n\ndiff --git a/Documentation/pull-fetch-param.txt b/Documentation/pull-fetch-param.txt\nindex 95ea84990298..95a7390b2c78 100644\n--- a/Documentation/pull-fetch-param.txt\n+++ b/Documentation/pull-fetch-param.txt\n@@ -30,6 +30,22 @@ The colon can be omitted when <dst> is empty.  <src> is\n typically a ref, but it can also be a fully spelled hex object\n name.\n +\n+A <refspec> may contain a `*` in its <src> to indicate a simple pattern\n+match. Such a refspec functions like a glob that matches any ref with the\n+same prefix. A pattern <refspec> must have a `*` in both the <src> and\n+<dst>. It will map refs to the destination by replacing the `*` with the\n+contents matched from the source.\n++\n+If a refspec is prefixed by `^`, it will be interpreted as a negative\n+refspec. Rather than specifying which refs to fetch or which local refs to\n+update, such a refspec will instead specify refs to exclude. A ref will be\n+considered to match if it matches at least one positive refspec, and does\n+not match any negative refspec. Negative refspecs can be useful to restrict\n+the scope of a pattern refspec so that it will not include specific refs.\n+Negative refspecs can themselves be pattern refspecs. However, they may only\n+contain a <src> and do not specify a <dst>. Fully spelled out hex object\n+names are also not supported.\n++\n `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`;\n it requests fetching everything up to the given tag.\n +\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 1b00c2bee90b..e95bf8877ddd 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -537,6 +537,16 @@ static struct ref *get_ref_map(struct remote *remote,\n \t\ttail = &rm->next;\n \t}\n \n+\t/*\n+\t * apply negative refspecs first, before we remove duplicates. This is\n+\t * necessary as negative refspecs might remove an otherwise conflicting\n+\t * duplicate.\n+\t */\n+\tif (rs->nr)\n+\t\tref_map = apply_negative_refspecs(ref_map, rs);\n+\telse\n+\t\tref_map = apply_negative_refspecs(ref_map, &remote->fetch);\n+\n \tref_map = ref_remove_duplicates(ref_map);\n \n \tfor (rm = ref_map; rm; rm = rm->next) {\ndiff --git a/refspec.c b/refspec.c\nindex 8d0affc34a6b..8af357a0a35d 100644\n--- a/refspec.c\n+++ b/refspec.c\n@@ -8,6 +8,7 @@ static struct refspec_item s_tag_refspec = {\n \t1,\n \t0,\n \t0,\n+\t0,\n \t\"refs/tags/*\",\n \t\"refs/tags/*\"\n };\n@@ -32,10 +33,17 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet\n \tif (*lhs == '+') {\n \t\titem->force = 1;\n \t\tlhs++;\n+\t} else if (*lhs == '^') {\n+\t\titem->negative = 1;\n+\t\tlhs++;\n \t}\n \n \trhs = strrchr(lhs, ':');\n \n+\t/* negative refspecs only have one side */\n+\tif (item->negative && rhs)\n+\t\treturn 0;\n+\n \t/*\n \t * Before going on, special case \":\" (or \"+:\") as a refspec\n \t * for pushing matching refs.\n@@ -55,7 +63,7 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet\n \n \tllen = (rhs ? (rhs - lhs - 1) : strlen(lhs));\n \tif (1 <= llen && memchr(lhs, '*', llen)) {\n-\t\tif ((rhs && !is_glob) || (!rhs && fetch))\n+\t\tif ((rhs && !is_glob) || (!rhs && !item->negative && fetch))\n \t\t\treturn 0;\n \t\tis_glob = 1;\n \t} else if (rhs && is_glob) {\n@@ -66,6 +74,28 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet\n \titem->src = xstrndup(lhs, llen);\n \tflags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);\n \n+\tif (item->negative) {\n+\t\tstruct object_id unused;\n+\n+\t\t/*\n+\t\t * Negative refspecs only have a LHS, which indicates a ref\n+\t\t * (or pattern of refs) to exclude from other matches. This\n+\t\t * can either be a simple ref, or a glob pattern. Exact sha1\n+\t\t * match is not currently supported.\n+\t\t */\n+\t\tif (!*item->src)\n+\t\t\treturn 0; /* negative refspecs must not be empty */\n+\t\telse if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))\n+\t\t\treturn 0; /* negative refpsecs cannot be exact sha1 */\n+\t\telse if (!check_refname_format(item->src, flags))\n+\t\t\t; /* valid looking ref is ok */\n+\t\telse\n+\t\t\treturn 0;\n+\n+\t\t/* the other rules below do not apply to negative refspecs */\n+\t\treturn 1;\n+\t}\n+\n \tif (fetch) {\n \t\tstruct object_id unused;\n \n@@ -223,7 +253,7 @@ void refspec_ref_prefixes(const struct refspec *rs,\n \t\tconst struct refspec_item *item = &rs->items[i];\n \t\tconst char *prefix = NULL;\n \n-\t\tif (item->exact_sha1)\n+\t\tif (item->exact_sha1 || item->negative)\n \t\t\tcontinue;\n \t\tif (rs->fetch == REFSPEC_FETCH)\n \t\t\tprefix = item->src;\ndiff --git a/refspec.h b/refspec.h\nindex 7569248d11b1..955183239923 100644\n--- a/refspec.h\n+++ b/refspec.h\n@@ -5,12 +5,13 @@\n extern const struct refspec_item *tag_refspec;\n \n /**\n- * A struct refspec_item holds the parsed interpretation of a refspec.  If it will\n- * force updates (starts with a '+'), force is true.  If it is a pattern\n- * (sides end with '*') pattern is true.  src and dest are the two sides\n- * (including '*' characters if present); if there is only one side, it is src,\n- * and dst is NULL; if sides exist but are empty (i.e., the refspec either\n- * starts or ends with ':'), the corresponding side is \"\".\n+ * A struct refspec_item holds the parsed interpretation of a refspec.  If it\n+ * will force updates (starts with a '+'), force is true.  If it is a pattern\n+ * (sides end with '*') pattern is true.  If it is a negative refspec, (starts\n+ * with '^'), negative is true.  src and dest are the two sides (including '*'\n+ * characters if present); if there is only one side, it is src, and dst is\n+ * NULL; if sides exist but are empty (i.e., the refspec either starts or ends\n+ * with ':'), the corresponding side is \"\".\n  *\n  * remote_find_tracking(), given a remote and a struct refspec_item with either src\n  * or dst filled out, will fill out the other such that the result is in the\n@@ -22,6 +23,7 @@ struct refspec_item {\n \tunsigned pattern : 1;\n \tunsigned matching : 1;\n \tunsigned exact_sha1 : 1;\n+\tunsigned negative : 1;\n \n \tchar *src;\n \tchar *dst;\ndiff --git a/remote.c b/remote.c\nindex eafc14cbe759..26a127142344 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -682,6 +682,91 @@ static int match_name_with_pattern(const char *key, const char *name,\n \treturn ret;\n }\n \n+static int refspec_match(const struct refspec_item *refspec,\n+\t\t\t const char *name)\n+{\n+\tif (refspec->pattern)\n+\t\treturn match_name_with_pattern(refspec->src, name, NULL, NULL);\n+\n+\treturn !strcmp(refspec->src, name);\n+}\n+\n+static int omit_name_by_refspec(const char *name, struct refspec *rs)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < rs->nr; i++) {\n+\t\tif (rs->items[i].negative && refspec_match(&rs->items[i], name))\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs)\n+{\n+\tstruct ref **tail;\n+\n+\tfor (tail = &ref_map; *tail; ) {\n+\t\tstruct ref *ref = *tail;\n+\n+\t\tif (omit_name_by_refspec(ref->name, rs)) {\n+\t\t\t*tail = ref->next;\n+\t\t\tfree(ref->peer_ref);\n+\t\t\tfree(ref);\n+\t\t} else\n+\t\t\ttail = &ref->next;\n+\t}\n+\n+\treturn ref_map;\n+}\n+\n+static int query_matches_negative_refspec(struct refspec *rs, struct refspec_item *query)\n+{\n+\tint i, matched_negative = 0;\n+\tint find_src = !query->src;\n+\tstruct string_list reversed = STRING_LIST_INIT_NODUP;\n+\tconst char *needle = find_src ? query->dst : query->src;\n+\n+\t/*\n+\t * Check whether the queried ref matches any negative refpsec. If so,\n+\t * then we should ultimately treat this as not matching the query at\n+\t * all.\n+\t *\n+\t * Note that negative refspecs always match the source, but the query\n+\t * item uses the destination. To handle this, we apply pattern\n+\t * refspecs in reverse to figure out if the query source matches any\n+\t * of the negative refspecs.\n+\t */\n+\tfor (i = 0; i < rs->nr; i++) {\n+\t\tstruct refspec_item *refspec = &rs->items[i];\n+\t\tchar *expn_name;\n+\n+\t\tif (refspec->negative)\n+\t\t\tcontinue;\n+\n+\t\t/* Note the reversal of src and dst */\n+\t\tif (refspec->pattern) {\n+\t\t\tconst char *key = refspec->dst ?: refspec->src;\n+\t\t\tconst char *value = refspec->src;\n+\n+\t\t\tif (match_name_with_pattern(key, needle, value, &expn_name))\n+\t\t\t\tstring_list_append_nodup(&reversed, expn_name);\n+\t\t} else {\n+\t\t\tif (!strcmp(needle, refspec->src))\n+\t\t\t\tstring_list_append(&reversed, refspec->src);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; !matched_negative && i < reversed.nr; i++) {\n+\t\tif (omit_name_by_refspec(reversed.items[i].string, rs))\n+\t\t\tmatched_negative = 1;\n+\t}\n+\n+\tstring_list_clear(&reversed, 0);\n+\n+\treturn matched_negative;\n+}\n+\n static void query_refspecs_multiple(struct refspec *rs,\n \t\t\t\t    struct refspec_item *query,\n \t\t\t\t    struct string_list *results)\n@@ -692,6 +777,9 @@ static void query_refspecs_multiple(struct refspec *rs,\n \tif (find_src && !query->dst)\n \t\tBUG(\"query_refspecs_multiple: need either src or dst\");\n \n+\tif (query_matches_negative_refspec(rs, query))\n+\t\treturn;\n+\n \tfor (i = 0; i < rs->nr; i++) {\n \t\tstruct refspec_item *refspec = &rs->items[i];\n \t\tconst char *key = find_src ? refspec->dst : refspec->src;\n@@ -699,7 +787,7 @@ static void query_refspecs_multiple(struct refspec *rs,\n \t\tconst char *needle = find_src ? query->dst : query->src;\n \t\tchar **result = find_src ? &query->src : &query->dst;\n \n-\t\tif (!refspec->dst)\n+\t\tif (!refspec->dst || refspec->negative)\n \t\t\tcontinue;\n \t\tif (refspec->pattern) {\n \t\t\tif (match_name_with_pattern(key, needle, value, result))\n@@ -720,12 +808,15 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)\n \tif (find_src && !query->dst)\n \t\tBUG(\"query_refspecs: need either src or dst\");\n \n+\tif (query_matches_negative_refspec(rs, query))\n+\t\treturn -1;\n+\n \tfor (i = 0; i < rs->nr; i++) {\n \t\tstruct refspec_item *refspec = &rs->items[i];\n \t\tconst char *key = find_src ? refspec->dst : refspec->src;\n \t\tconst char *value = find_src ? refspec->src : refspec->dst;\n \n-\t\tif (!refspec->dst)\n+\t\tif (!refspec->dst || refspec->negative)\n \t\t\tcontinue;\n \t\tif (refspec->pattern) {\n \t\t\tif (match_name_with_pattern(key, needle, value, result)) {\n@@ -1054,7 +1145,7 @@ static int match_explicit(struct ref *src, struct ref *dst,\n \tconst char *dst_value = rs->dst;\n \tchar *dst_guess;\n \n-\tif (rs->pattern || rs->matching)\n+\tif (rs->pattern || rs->matching || rs->negative)\n \t\treturn 0;\n \n \tmatched_src = matched_dst = NULL;\n@@ -1130,6 +1221,10 @@ static char *get_ref_match(const struct refspec *rs, const struct ref *ref,\n \tint matching_refs = -1;\n \tfor (i = 0; i < rs->nr; i++) {\n \t\tconst struct refspec_item *item = &rs->items[i];\n+\n+\t\tif (item->negative)\n+\t\t\tcontinue;\n+\n \t\tif (item->matching &&\n \t\t    (matching_refs == -1 || item->force)) {\n \t\t\tmatching_refs = i;\n@@ -1335,7 +1430,7 @@ int check_push_refs(struct ref *src, struct refspec *rs)\n \tfor (i = 0; i < rs->nr; i++) {\n \t\tstruct refspec_item *item = &rs->items[i];\n \n-\t\tif (item->pattern || item->matching)\n+\t\tif (item->pattern || item->matching || item->negative)\n \t\t\tcontinue;\n \n \t\tret |= match_explicit_lhs(src, item, NULL, NULL);\n@@ -1437,6 +1532,8 @@ int match_push_refs(struct ref *src, struct ref **dst,\n \t\tstring_list_clear(&src_ref_index, 0);\n \t}\n \n+\t*dst = apply_negative_refspecs(*dst, rs);\n+\n \tif (errs)\n \t\treturn -1;\n \treturn 0;\n@@ -1806,6 +1903,9 @@ int get_fetch_map(const struct ref *remote_refs,\n {\n \tstruct ref *ref_map, **rmp;\n \n+\tif (refspec->negative)\n+\t\treturn 0;\n+\n \tif (refspec->pattern) {\n \t\tref_map = get_expanded_map(remote_refs, refspec);\n \t} else {\ndiff --git a/remote.h b/remote.h\nindex 5e3ea5a26deb..104e75e0f74d 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -193,6 +193,12 @@ int resolve_remote_symref(struct ref *ref, struct ref *list);\n  */\n struct ref *ref_remove_duplicates(struct ref *ref_map);\n \n+/*\n+ * Remove all entries in the input list which match any negative refspec in\n+ * the refspec list.\n+ */\n+struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs);\n+\n int query_refspecs(struct refspec *rs, struct refspec_item *query);\n char *apply_refspecs(struct refspec *rs, const char *name);\n \n@@ -205,7 +211,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n /*\n  * Given a list of the remote refs and the specification of things to\n  * fetch, makes a (separate) list of the refs to fetch and the local\n- * refs to store into.\n+ * refs to store into. Note that negative refspecs are ignored here, and\n+ * should be handled separately.\n  *\n  * *tail is the pointer to the tail pointer of the list of results\n  * beforehand, and will be set to the tail pointer of the list of\ndiff --git a/t/t5582-fetch-negative-refspec.sh b/t/t5582-fetch-negative-refspec.sh\nnew file mode 100755\nindex 000000000000..8c61e28fec85\n--- /dev/null\n+++ b/t/t5582-fetch-negative-refspec.sh\n@@ -0,0 +1,189 @@\n+#!/bin/sh\n+# Copyright (c) 2020, Jacob Keller.\n+\n+test_description='\"git fetch\" with negative refspecs.\n+\n+'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo >file original &&\n+\tgit add file &&\n+\tgit commit -a -m original\n+'\n+\n+test_expect_success \"clone and setup child repos\" '\n+\tgit clone . one &&\n+\t(\n+\t\tcd one &&\n+\t\techo >file updated by one &&\n+\t\tgit commit -a -m \"updated by one\" &&\n+\t\tgit switch -c alternate &&\n+\t\techo >file updated again by one &&\n+\t\tgit commit -a -m \"updated by one again\" &&\n+\t\tgit switch master\n+\t) &&\n+\tgit clone . two &&\n+\t(\n+\t\tcd two &&\n+\t\tgit config branch.master.remote one &&\n+\t\tgit config remote.one.url ../one/.git/ &&\n+\t\tgit config remote.one.fetch +refs/heads/*:refs/remotes/one/* &&\n+\t\tgit config --add remote.one.fetch ^refs/heads/alternate\n+\t) &&\n+\tgit clone . three\n+'\n+\n+test_expect_success \"fetch one\" '\n+\techo >file updated by origin &&\n+\tgit commit -a -m \"updated by origin\" &&\n+\t(\n+\t\tcd two &&\n+\t\ttest_must_fail git rev-parse --verify refs/remotes/one/alternate &&\n+\t\tgit fetch one &&\n+\t\ttest_must_fail git rev-parse --verify refs/remotes/one/alternate &&\n+\t\tgit rev-parse --verify refs/remotes/one/master &&\n+\t\tmine=$(git rev-parse refs/remotes/one/master) &&\n+\t\this=$(cd ../one && git rev-parse refs/heads/master) &&\n+\t\ttest \"z$mine\" = \"z$his\"\n+\t)\n+'\n+\n+test_expect_success \"fetch with negative refspec on commandline\" '\n+\techo >file updated by origin again &&\n+\tgit commit -a -m \"updated by origin again\" &&\n+\t(\n+\t\tcd three &&\n+\t\talternate_in_one=$(cd ../one && git rev-parse refs/heads/alternate) &&\n+\t\techo $alternate_in_one >expect &&\n+\t\tgit fetch ../one/.git refs/heads/*:refs/remotes/one/* ^refs/heads/master &&\n+\t\tcut -f -1 .git/FETCH_HEAD >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success \"fetch with negative sha1 refspec fails\" '\n+\techo >file updated by origin yet again &&\n+\tgit commit -a -m \"updated by origin yet again\" &&\n+\t(\n+\t\tcd three &&\n+\t\tmaster_in_one=$(cd ../one && git rev-parse refs/heads/master) &&\n+\t\ttest_must_fail git fetch ../one/.git refs/heads/*:refs/remotes/one/* ^$master_in_one\n+\t)\n+'\n+\n+test_expect_success \"fetch with negative pattern refspec\" '\n+\techo >file updated by origin once more &&\n+\tgit commit -a -m \"updated by origin once more\" &&\n+\t(\n+\t\tcd three &&\n+\t\talternate_in_one=$(cd ../one && git rev-parse refs/heads/alternate) &&\n+\t\techo $alternate_in_one >expect &&\n+\t\tgit fetch ../one/.git refs/heads/*:refs/remotes/one/* ^refs/heads/m* &&\n+\t\tcut -f -1 .git/FETCH_HEAD >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success \"fetch with negative pattern refspec does not expand prefix\" '\n+\techo >file updated by origin another time &&\n+\tgit commit -a -m \"updated by origin another time\" &&\n+\t(\n+\t\tcd three &&\n+\t\talternate_in_one=$(cd ../one && git rev-parse refs/heads/alternate) &&\n+\t\tmaster_in_one=$(cd ../one && git rev-parse refs/heads/master) &&\n+\t\techo $alternate_in_one >expect &&\n+\t\techo $master_in_one >>expect &&\n+\t\tgit fetch ../one/.git refs/heads/*:refs/remotes/one/* ^master &&\n+\t\tcut -f -1 .git/FETCH_HEAD >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success \"fetch with negative refspec avoids duplicate conflict\" '\n+\tcd \"$D\" &&\n+\t(\n+\t\tcd one &&\n+\t\tgit branch dups/a &&\n+\t\tgit branch dups/b &&\n+\t\tgit branch dups/c &&\n+\t\tgit branch other/a &&\n+\t\tgit rev-parse --verify refs/heads/other/a >../expect &&\n+\t\tgit rev-parse --verify refs/heads/dups/b >>../expect &&\n+\t\tgit rev-parse --verify refs/heads/dups/c >>../expect\n+\t) &&\n+\t(\n+\t\tcd three &&\n+\t\tgit fetch ../one/.git ^refs/heads/dups/a refs/heads/dups/*:refs/dups/* refs/heads/other/a:refs/dups/a &&\n+\t\tgit rev-parse --verify refs/dups/a >../actual &&\n+\t\tgit rev-parse --verify refs/dups/b >>../actual &&\n+\t\tgit rev-parse --verify refs/dups/c >>../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \"push --prune with negative refspec\" '\n+\t(\n+\t\tcd two &&\n+\t\tgit branch prune/a &&\n+\t\tgit branch prune/b &&\n+\t\tgit branch prune/c &&\n+\t\tgit push ../three refs/heads/prune/* &&\n+\t\tgit branch -d prune/a &&\n+\t\tgit branch -d prune/b &&\n+\t\tgit push --prune ../three refs/heads/prune/* ^refs/heads/prune/b\n+\t) &&\n+\t(\n+\t\tcd three &&\n+\t\ttest_write_lines b c >expect &&\n+\t\tgit for-each-ref --format=\"%(refname:lstrip=3)\" refs/heads/prune/ >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success \"push --prune with negative refspec apply to the destination\" '\n+\t(\n+\t\tcd two &&\n+\t\tgit branch ours/a &&\n+\t\tgit branch ours/b &&\n+\t\tgit branch ours/c &&\n+\t\tgit push ../three refs/heads/ours/*:refs/heads/theirs/* &&\n+\t\tgit branch -d ours/a &&\n+\t\tgit branch -d ours/b &&\n+\t\tgit push --prune ../three refs/heads/ours/*:refs/heads/theirs/* ^refs/heads/theirs/b\n+\t) &&\n+\t(\n+\t\tcd three &&\n+\t\ttest_write_lines b c >expect &&\n+\t\tgit for-each-ref --format=\"%(refname:lstrip=3)\" refs/heads/theirs/ >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success \"fetch --prune with negative refspec\" '\n+\t(\n+\t\tcd two &&\n+\t\tgit branch fetch/a &&\n+\t\tgit branch fetch/b &&\n+\t\tgit branch fetch/c\n+\t) &&\n+\t(\n+\t\tcd three &&\n+\t\tgit fetch ../two/.git refs/heads/fetch/*:refs/heads/copied/*\n+\t) &&\n+\t(\n+\t\tcd two &&\n+\t\tgit branch -d fetch/a &&\n+\t\tgit branch -d fetch/b\n+\t) &&\n+\t(\n+\t\tcd three &&\n+\t\ttest_write_lines b c >expect &&\n+\t\tgit fetch -v ../two/.git --prune refs/heads/fetch/*:refs/heads/copied/* ^refs/heads/fetch/b &&\n+\t\tgit for-each-ref --format=\"%(refname:lstrip=3)\" refs/heads/copied/ >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_done\n-- \n2.28.0.497.g54e85e7af1ac\n\n"},{"id":"406715","messageId":"CAPig+cQUeQV0=LDQ_tY43k6z7km4X6Fm9JJVPUBoG=wY3gxDfw@mail.gmail.com","threadId":"54331","inReplyTo":"20200930212529.100458-1-jacob.e.keller@intel.com","subject":"Re: [v4] refspec: add support for negative refspecs","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-09-30T21:34:02Z","receivedAt":"2020-09-30T21:34:28Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Sep 30, 2020 at 5:26 PM Jacob Keller <jacob.e.keller@intel.com> wrote:\n> Changes since v3\n> * removed the ?: usage (for real this time)\n>\n> +               /* Note the reversal of src and dst */\n> +               if (refspec->pattern) {\n> +                       const char *key = refspec->dst ?: refspec->src;\n\nBlorp.\n"},{"id":"406717","messageId":"xmqqr1qjexmg.fsf@gitster.c.googlers.com","threadId":"54331","inReplyTo":"CAPig+cQUeQV0=LDQ_tY43k6z7km4X6Fm9JJVPUBoG=wY3gxDfw@mail.gmail.com","subject":"Re: [v4] refspec: add support for negative refspecs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-09-30T21:57:27Z","receivedAt":"2020-09-30T21:57:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Wed, Sep 30, 2020 at 5:26 PM Jacob Keller <jacob.e.keller@intel.com> wrote:\n>> Changes since v3\n>> * removed the ?: usage (for real this time)\n>>\n>> +               /* Note the reversal of src and dst */\n>> +               if (refspec->pattern) {\n>> +                       const char *key = refspec->dst ?: refspec->src;\n>\n> Blorp.\n\nWoof.\n\nHave squashed this in.\n\n remote.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/remote.c b/remote.c\nindex 9f8b25674e..dad3b79332 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -750,7 +750,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite\n \n \t\t/* Note the reversal of src and dst */\n \t\tif (refspec->pattern) {\n-\t\t\tconst char *key = refspec->dst ?: refspec->src;\n+\t\t\tconst char *key = refspec->dst ? refspec->dst : refspec->src;\n \t\t\tconst char *value = refspec->src;\n \n \t\t\tif (match_name_with_pattern(key, needle, value, &expn_name))\n"},{"id":"406719","messageId":"CA+P7+xoTXrjik5fqSN1Qndek8hyaSdTtn=88hRnxLCmRMhdQyg@mail.gmail.com","threadId":"54331","inReplyTo":"CAPig+cQUeQV0=LDQ_tY43k6z7km4X6Fm9JJVPUBoG=wY3gxDfw@mail.gmail.com","subject":"Re: [v4] refspec: add support for negative refspecs","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-09-30T22:00:39Z","receivedAt":"2020-09-30T22:00:54Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Wed, Sep 30, 2020 at 2:34 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Wed, Sep 30, 2020 at 5:26 PM Jacob Keller <jacob.e.keller@intel.com> wrote:\n> > Changes since v3\n> > * removed the ?: usage (for real this time)\n> >\n> > +               /* Note the reversal of src and dst */\n> > +               if (refspec->pattern) {\n> > +                       const char *key = refspec->dst ?: refspec->src;\n>\n> Blorp.\n\n.... I am very confused....   I made this change...\n\n$git diff doesn't show anything...\n\nOh.. wooooops. git status has it as staged but not applied..\n\nSigh. I sent another round.\n"},{"id":"406720","messageId":"CA+P7+xqs4avU5y32jVMTRB8f0MJ8JjFoWE9mFffh7JrnCWaZMw@mail.gmail.com","threadId":"54331","inReplyTo":"xmqqr1qjexmg.fsf@gitster.c.googlers.com","subject":"Re: [v4] refspec: add support for negative refspecs","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-09-30T22:01:13Z","receivedAt":"2020-09-30T22:01:31Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Wed, Sep 30, 2020 at 2:57 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n>\n> > On Wed, Sep 30, 2020 at 5:26 PM Jacob Keller <jacob.e.keller@intel.com> wrote:\n> >> Changes since v3\n> >> * removed the ?: usage (for real this time)\n> >>\n> >> +               /* Note the reversal of src and dst */\n> >> +               if (refspec->pattern) {\n> >> +                       const char *key = refspec->dst ?: refspec->src;\n> >\n> > Blorp.\n>\n> Woof.\n>\n> Have squashed this in.\n>\n>  remote.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n\nI sent a v5 too.. Lol\n\nClearly just not my day today\n\nThanks,\nJake\n\n> diff --git a/remote.c b/remote.c\n> index 9f8b25674e..dad3b79332 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -750,7 +750,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite\n>\n>                 /* Note the reversal of src and dst */\n>                 if (refspec->pattern) {\n> -                       const char *key = refspec->dst ?: refspec->src;\n> +                       const char *key = refspec->dst ? refspec->dst : refspec->src;\n>                         const char *value = refspec->src;\n>\n>                         if (match_name_with_pattern(key, needle, value, &expn_name))\n"}]}