Skip to content

Commit

Permalink
refspec: make sure matching refspecs have src, dst and input strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlosmn committed Jun 22, 2015
1 parent c62ab5f commit 6ba8a33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/refspec.c
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/network/refspecs.c
Expand Up @@ -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);
}

0 comments on commit 6ba8a33

Please sign in to comment.