aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache.h1
-rw-r--r--refs.c7
-rw-r--r--remote.c23
-rwxr-xr-xt/t5510-fetch.sh25
4 files changed, 35 insertions, 21 deletions
diff --git a/cache.h b/cache.h
index 38d9a285e..cb8f3cabb 100644
--- a/cache.h
+++ b/cache.h
@@ -417,6 +417,7 @@ extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
extern const char *ref_rev_parse_rules[];
+extern const char *ref_fetch_rules[];
extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg);
extern int validate_headref(const char *ref);
diff --git a/refs.c b/refs.c
index fc26a93cb..6a04a667b 100644
--- a/refs.c
+++ b/refs.c
@@ -653,6 +653,13 @@ const char *ref_rev_parse_rules[] = {
NULL
};
+const char *ref_fetch_rules[] = {
+ "%.*s",
+ "refs/%.*s",
+ "refs/heads/%.*s",
+ NULL
+};
+
int refname_match(const char *abbrev_name, const char *full_name, const char **rules)
{
const char **p;
diff --git a/remote.c b/remote.c
index 4085c517e..48812a713 100644
--- a/remote.c
+++ b/remote.c
@@ -417,25 +417,6 @@ int remote_has_url(struct remote *remote, const char *url)
return 0;
}
-/*
- * Returns true if, under the matching rules for fetching, name is the
- * same as the given full name.
- */
-static int ref_matches_abbrev(const char *name, const char *full)
-{
- if (!prefixcmp(name, "refs/") || !strcmp(name, "HEAD"))
- return !strcmp(name, full);
- if (prefixcmp(full, "refs/"))
- return 0;
- if (!prefixcmp(name, "heads/") ||
- !prefixcmp(name, "tags/") ||
- !prefixcmp(name, "remotes/"))
- return !strcmp(name, full + 5);
- if (prefixcmp(full + 5, "heads/"))
- return 0;
- return !strcmp(full + 11, name);
-}
-
int remote_find_tracking(struct remote *remote, struct refspec *refspec)
{
int find_src = refspec->src == NULL;
@@ -804,7 +785,7 @@ int branch_merge_matches(struct branch *branch,
{
if (!branch || i < 0 || i >= branch->merge_nr)
return 0;
- return ref_matches_abbrev(branch->merge[i]->src, refname);
+ return refname_match(branch->merge[i]->src, refname, ref_fetch_rules);
}
static struct ref *get_expanded_map(struct ref *remote_refs,
@@ -843,7 +824,7 @@ static struct ref *find_ref_by_name_abbrev(struct ref *refs, const char *name)
{
struct ref *ref;
for (ref = refs; ref; ref = ref->next) {
- if (ref_matches_abbrev(name, ref->name))
+ if (refname_match(name, ref->name, ref_fetch_rules))
return ref;
}
return NULL;
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index aad863db7..20257428e 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -95,6 +95,31 @@ test_expect_success 'fetch following tags' '
'
+test_expect_failure 'fetch must not resolve short tag name' '
+
+ cd "$D" &&
+
+ mkdir five &&
+ cd five &&
+ git init &&
+
+ git fetch .. anno:five
+
+'
+
+test_expect_failure 'fetch must not resolve short remote name' '
+
+ cd "$D" &&
+ git-update-ref refs/remotes/six/HEAD HEAD
+
+ mkdir six &&
+ cd six &&
+ git init &&
+
+ git fetch .. six:six
+
+'
+
test_expect_success 'create bundle 1' '
cd "$D" &&
echo >file updated again by origin &&