summaryrefslogtreecommitdiff
path: root/tests/network/refspecs.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-04-26 10:38:02 +0200
committerPatrick Steinhardt <ps@pks.im>2019-04-26 10:38:02 +0200
commit0c71e4cbd646a62fcbe534532178e841107d232d (patch)
tree4536d5f878985d754a265890c93cb37d8c369076 /tests/network/refspecs.c
parent51214b85dedc39b734cce9d09b9311221a31de4b (diff)
downloadlibgit2-0c71e4cbd646a62fcbe534532178e841107d232d.tar.gz
refspec: fix transforming nested stars
When we transform a refspec with a component containing a glob, then we simply copy over the component until the next separator from the matching ref. E.g. if we have a ref "refs/heads/foo/bar" and a refspec "refs/heads/*/bar:refs/remotes/origin/*/bar", we: 1. Copy over everything until hitting the glob from the <dst> part: "refs/remotes/origin/". 2. Strip the common prefix of ref and <src> part until the glob, which is "refs/heads/". This leaves us with a ref of "foo/bar". 3. Copy from the ref until the next "/" separator, resulting in "refs/remotes/origin/foo". 4. Copy over the remaining part of the <dst> spec, which is "bar": "refs/remotes/origin/foo/bar". This worked just fine in a world where globs in refspecs were restricted such that a globbing component may only contain a single "*", only. But this restriction has been lifted, so that a glob component may be nested between other characters, causing the above algorithm to fail. Most notably the third step, where we copy until hitting the next "/" separator, might result in a wrong transformation. Given e.g. a ref "refs/gbranchg/head" and a refspec "refs/g*g/head:refs/remotes/origin/*", we'd also be copying the "g" between "branch" and "/" and end up with the wrong transformed ref "refs/remotes/origin/branchg". Instead of copying until the next component separator, we should copy until we hit the pattern after the "*". So in the above example, we'd copy until hitting the string "g/head".
Diffstat (limited to 'tests/network/refspecs.c')
-rw-r--r--tests/network/refspecs.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/network/refspecs.c b/tests/network/refspecs.c
index 9df0a764f..734759060 100644
--- a/tests/network/refspecs.c
+++ b/tests/network/refspecs.c
@@ -120,6 +120,11 @@ void test_network_refspecs__transform_loosened_star(void)
assert_valid_transform("refs/heads/branch-*/head:refs/remotes/origin/branch-*/head", "refs/heads/branch-a/head", "refs/remotes/origin/branch-a/head");
}
+void test_network_refspecs__transform_nested_star(void)
+{
+ assert_valid_transform("refs/heads/x*x/for-linus:refs/remotes/mine/*", "refs/heads/xbranchx/for-linus", "refs/remotes/mine/branch");
+}
+
void test_network_refspecs__no_dst(void)
{
assert_valid_transform("refs/heads/master:", "refs/heads/master", "");