From: Junio C Hamano Date: Sun, 10 Jan 2010 16:52:10 +0000 (-0800) Subject: Merge branch 'mm/diag-path-in-treeish' X-Git-Tag: v1.7.0-rc0~115 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2b35fccf734ab1d30828d95ea34f1755d9183365?ds=inline;hp=-c Merge branch 'mm/diag-path-in-treeish' * mm/diag-path-in-treeish: Detailed diagnosis when parsing an object name fails. --- 2b35fccf734ab1d30828d95ea34f1755d9183365 diff --combined setup.c index 2cf0f19937,5792eb7ddf..3a07aa4df7 --- a/setup.c +++ b/setup.c @@@ -18,12 -18,9 +18,12 @@@ const char *prefix_path(const char *pre if (normalize_path_copy(sanitized, sanitized)) goto error_out; if (is_absolute_path(orig)) { + size_t len, total; const char *work_tree = get_git_work_tree(); - size_t len = strlen(work_tree); - size_t total = strlen(sanitized) + 1; + if (!work_tree) + goto error_out; + len = strlen(work_tree); + total = strlen(sanitized) + 1; if (strncmp(sanitized, work_tree, len) || (sanitized[len] != '\0' && sanitized[len] != '/')) { error_out: @@@ -77,6 -74,18 +77,18 @@@ int check_filename(const char *prefix, die_errno("failed to stat '%s'", arg); } + static void NORETURN die_verify_filename(const char *prefix, const char *arg) + { + unsigned char sha1[20]; + unsigned mode; + /* try a detailed diagnostic ... */ + get_sha1_with_mode_1(arg, sha1, &mode, 0, prefix); + /* ... or fall back the most general message. */ + die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" + "Use '--' to separate paths from revisions", arg); + + } + /* * Verify a filename that we got as an argument for a pathspec * entry. Note that a filename that begins with "-" never verifies @@@ -90,8 -99,7 +102,7 @@@ void verify_filename(const char *prefix die("bad flag '%s' used after filename", arg); if (check_filename(prefix, arg)) return; - die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" - "Use '--' to separate paths from revisions", arg); + die_verify_filename(prefix, arg); } /*