summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-05-22 12:11:42 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-06-22 18:18:14 +0200
commit6ba8a33d69ce19e27ddcc3be9cd397c2550b0efc (patch)
treef8c58a3c9c696b30ecbb28cb41a3381a80c09b03
parentc62ab5f5dad62e9a381314e81d188c506e9ef0b7 (diff)
downloadlibgit2-6ba8a33d69ce19e27ddcc3be9cd397c2550b0efc.tar.gz
refspec: make sure matching refspecs have src, dst and input strings
When we find out that we're dealing with a matching refspec, we set the flag and return immediately. This leaves the strings as NULL, which breaks the contract. Assign these pointers to a string with the correct values.
-rw-r--r--src/refspec.c6
-rw-r--r--tests/network/refspecs.c10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/refspec.c b/src/refspec.c
index a56c44cc0..b6db5a834 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -42,6 +42,12 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
*/
if (!is_fetch && rhs == lhs && rhs[1] == '\0') {
refspec->matching = 1;
+ refspec->string = git__strdup(input);
+ GITERR_CHECK_ALLOC(refspec->string);
+ refspec->src = git__strdup("");
+ GITERR_CHECK_ALLOC(refspec->src);
+ refspec->dst = git__strdup("");
+ GITERR_CHECK_ALLOC(refspec->dst);
return 0;
}
diff --git a/tests/network/refspecs.c b/tests/network/refspecs.c
index c6bcb10e8..614d91d07 100644
--- a/tests/network/refspecs.c
+++ b/tests/network/refspecs.c
@@ -146,3 +146,13 @@ void test_network_refspecs__invalid_reverse(void)
assert_invalid_rtransform("refs/heads/*:refs/remotes/origin/*", "master");
assert_invalid_rtransform("refs/heads/*:refs/remotes/origin/*", "refs/remotes/o/master");
}
+
+void test_network_refspecs__matching(void)
+{
+ git_refspec spec;
+
+ cl_git_pass(git_refspec__parse(&spec, ":", false));
+ cl_assert_equal_s(":", spec.string);
+ cl_assert_equal_s("", spec.src);
+ cl_assert_equal_s("", spec.dst);
+}