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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
471fd3fe41
commit
ba928c13d7
25
remote.c
25
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
|
||||
|
Reference in New Issue
Block a user