Check that the refspec matches before modifying the out buffer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/src/refspec.c b/src/refspec.c
index 8689769..9f0df35 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -226,14 +226,14 @@ int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *nam
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;
}
+ if (!spec->pattern)
+ return git_buf_puts(out, spec->dst);
+
return refspec_transform(out, spec->src, spec->dst, name);
}
@@ -242,14 +242,14 @@ int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *na
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;
}
+ if (!spec->pattern)
+ return git_buf_puts(out, spec->src);
+
return refspec_transform(out, spec->dst, spec->src, name);
}