diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-08-17 23:09:55 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-08-17 23:09:55 +0300 |
commit | 72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0 (patch) | |
tree | 3ae354187efd31883707de12020f700e2d128c9e /remote.c | |
parent | 60858f343aa909305c28790c7684bf88905695a2 (diff) | |
parent | 60650a48c0b24ecf64468426ec13b88c07069b28 (diff) |
Merge branch 'jt/refspec-dwim-precedence-fix'
"git fetch $there refs/heads/s" ought to fetch the tip of the
branch 's', but when "refs/heads/refs/heads/s", i.e. a branch whose
name is "refs/heads/s" exists at the same time, fetched that one
instead by mistake. This has been corrected to honor the usual
disambiguation rules for abbreviated refnames.
* jt/refspec-dwim-precedence-fix:
remote: make refspec follow the same disambiguation rule as local refs
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -1689,11 +1689,18 @@ static struct ref *get_expanded_map(const struct ref *remote_refs, static const struct ref *find_ref_by_name_abbrev(const struct ref *refs, const char *name) { const struct ref *ref; + const struct ref *best_match = NULL; + int best_score = 0; + for (ref = refs; ref; ref = ref->next) { - if (refname_match(name, ref->name)) - return ref; + int score = refname_match(name, ref->name); + + if (best_score < score) { + best_match = ref; + best_score = score; + } } - return NULL; + return best_match; } struct ref *get_remote_ref(const struct ref *remote_refs, const char *name) |