summaryrefslogtreecommitdiff
path: root/src/refspec.c
diff options
context:
space:
mode:
authorJacques Germishuys <jacquesg@striata.com>2014-08-17 14:55:06 +0200
committerJacques Germishuys <jacquesg@striata.com>2014-08-17 14:55:06 +0200
commit4e53c28096f4b04ab9b573fc594a538f51e10049 (patch)
tree71ffc739c341a49bb13e8430f7663a861cd6d449 /src/refspec.c
parentfa44a1699ccd70725b236868ef4be5cac8c36267 (diff)
downloadlibgit2-4e53c28096f4b04ab9b573fc594a538f51e10049.tar.gz
Check if the refspec matches before transforming
Diffstat (limited to 'src/refspec.c')
-rw-r--r--src/refspec.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/refspec.c b/src/refspec.c
index 77c58c84e..8689769f3 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -223,21 +223,33 @@ static int refspec_transform(
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{
- git_buf_sanitize(out);
+ assert(out && spec && name);
+ git_buf_sanitize(out);
if (!spec->pattern)
return git_buf_puts(out, spec->dst);
+ if (!git_refspec_src_matches(spec, name)) {
+ giterr_set(GITERR_INVALID, "ref '%s' doesn't match the source", name);
+ return -1;
+ }
+
return refspec_transform(out, spec->src, spec->dst, name);
}
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{
- git_buf_sanitize(out);
+ assert(out && spec && name);
+ git_buf_sanitize(out);
if (!spec->pattern)
return git_buf_puts(out, spec->src);
+ if (!git_refspec_dst_matches(spec, name)) {
+ giterr_set(GITERR_INVALID, "ref '%s' doesn't match the destination", name);
+ return -1;
+ }
+
return refspec_transform(out, spec->dst, spec->src, name);
}