From ba928c13d75172799f5f06f922e5c2f3232cf114 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 5 Mar 2014 14:04:54 -0500 Subject: push: detect local refspec errors early When pushing, we do not even look at our push refspecs until after we have made contact with the remote receive-pack and gotten its list of refs. This means that we may go to some work, including asking the user to log in, before realizing we have simple errors like "git push origin matser". We cannot catch all refspec problems, since fully evaluating the refspecs requires knowing what the remote side has. But we can do a quick sanity check of the local side and catch a few simple error cases. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- remote.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'remote.c') diff --git a/remote.c b/remote.c index b6586c089f..9bf498af1b 100644 --- a/remote.c +++ b/remote.c @@ -1373,6 +1373,31 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref) sort_string_list(ref_index); } +/* + * Given only the set of local refs, sanity-check the set of push + * refspecs. We can't catch all errors that match_push_refs would, + * but we can catch some errors early before even talking to the + * remote side. + */ +int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) +{ + struct refspec *refspec = parse_push_refspec(nr_refspec, refspec_names); + int ret = 0; + int i; + + for (i = 0; i < nr_refspec; i++) { + struct refspec *rs = refspec + i; + + if (rs->pattern || rs->matching) + continue; + + ret |= match_explicit_lhs(src, rs, NULL, NULL); + } + + free_refspec(nr_refspec, refspec); + return ret; +} + /* * Given the set of refs the local repository has, the set of refs the * remote repository has, and the refspec used for push, determine -- cgit v1.2.1