aboutsummaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-03-20 18:45:47 -0800
committerJunio C Hamano <junkio@cox.net>2006-03-20 23:34:17 -0800
commit2f8acdb38e513e4b983209563faf4c1d38c4013e (patch)
tree2f6b03268adeaabee94444387ed6537c63f90b31 /sha1_name.c
parentac7490506418e3ec495775e432b7040a17449fa9 (diff)
downloadgit-2f8acdb38e513e4b983209563faf4c1d38c4013e.tar.gz
git-2f8acdb38e513e4b983209563faf4c1d38c4013e.tar.xz
core.warnambiguousrefs: warns when "name" is used and both "name" branch and tag exists.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/sha1_name.c b/sha1_name.c
index d67de18ba..74c479c5e 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -240,9 +240,13 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
"refs",
"refs/tags",
"refs/heads",
+ "refs/remotes",
NULL
};
const char **p;
+ const char *warning = "warning: refname '%.*s' is ambiguous.\n";
+ char *pathname;
+ int already_found = 0;
if (len == 40 && !get_sha1_hex(str, sha1))
return 0;
@@ -252,10 +256,23 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
return -1;
for (p = prefix; *p; p++) {
- char *pathname = git_path("%s/%.*s", *p, len, str);
- if (!read_ref(pathname, sha1))
- return 0;
+ unsigned char sha1_from_ref[20];
+ unsigned char *this_result =
+ already_found ? sha1_from_ref : sha1;
+ pathname = git_path("%s/%.*s", *p, len, str);
+ if (!read_ref(pathname, this_result)) {
+ if (warn_ambiguous_refs) {
+ if (already_found &&
+ !memcmp(sha1, sha1_from_ref, 20))
+ fprintf(stderr, warning, len, str);
+ already_found++;
+ }
+ else
+ return 0;
+ }
}
+ if (already_found)
+ return 0;
return -1;
}