vendor/libgit2/src/refspec.c in rugged-0.21.4 vs vendor/libgit2/src/refspec.c in rugged-0.22.0b1

- old
+ new

@@ -117,10 +117,16 @@ goto invalid; } else { if (!git_reference__is_valid_name(refspec->dst, flags)) goto invalid; } + + /* if the RHS is empty, then it's a copy of the LHS */ + if (!refspec->dst) { + refspec->dst = git__strdup(refspec->src); + GITERR_CHECK_ALLOC(refspec->dst); + } } refspec->string = git__strdup(input); GITERR_CHECK_ALLOC(refspec->string); @@ -221,20 +227,32 @@ return git_buf_puts(out, to_star + 1); } 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 (!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); } 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 (!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);