summaryrefslogtreecommitdiff
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
parentac7490506418e3ec495775e432b7040a17449fa9 (diff)
downloadgit-2f8acdb38e513e4b983209563faf4c1d38c4013e.tar.gz
core.warnambiguousrefs: warns when "name" is used and both "name" branch and tag exists.
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--cache.h1
-rw-r--r--config.c5
-rw-r--r--environment.c1
-rw-r--r--sha1_name.c23
4 files changed, 27 insertions, 3 deletions
diff --git a/cache.h b/cache.h
index 1f962809b0..255e6b5cc7 100644
--- a/cache.h
+++ b/cache.h
@@ -165,6 +165,7 @@ extern void rollback_index_file(struct cache_file *);
extern int trust_executable_bit;
extern int assume_unchanged;
extern int only_use_symrefs;
+extern int warn_ambiguous_refs;
extern int diff_rename_limit_default;
extern int shared_repository;
extern const char *apply_default_whitespace;
diff --git a/config.c b/config.c
index 7dbdce1966..95ec34923d 100644
--- a/config.c
+++ b/config.c
@@ -232,6 +232,11 @@ int git_default_config(const char *var, const char *value)
return 0;
}
+ if (!strcmp(var, "core.warnambiguousrefs")) {
+ warn_ambiguous_refs = git_config_bool(var, value);
+ return 0;
+ }
+
if (!strcmp(var, "user.name")) {
strncpy(git_default_name, value, sizeof(git_default_name));
return 0;
diff --git a/environment.c b/environment.c
index 16c08f0697..5d29b92bd5 100644
--- a/environment.c
+++ b/environment.c
@@ -14,6 +14,7 @@ char git_default_name[MAX_GITNAME];
int trust_executable_bit = 1;
int assume_unchanged = 0;
int only_use_symrefs = 0;
+int warn_ambiguous_refs = 0;
int repository_format_version = 0;
char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
int shared_repository = 0;
diff --git a/sha1_name.c b/sha1_name.c
index d67de18ba5..74c479c5e6 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;
}