summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-17 20:09:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-17 20:09:55 (GMT)
commit72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0 (patch)
tree3ae354187efd31883707de12020f700e2d128c9e /remote.c
parent60858f343aa909305c28790c7684bf88905695a2 (diff)
parent60650a48c0b24ecf64468426ec13b88c07069b28 (diff)
downloadgit-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.zip
git-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.tar.gz
git-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.tar.bz2
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.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/remote.c b/remote.c
index 86e6098..7f6277a 100644
--- a/remote.c
+++ b/remote.c
@@ -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)