53
die_errno("failed to stat '%s'", arg);
54
}
55
56
-static void NORETURN die_verify_filename(const char *prefix, const char *arg)
56
+static void NORETURN die_verify_filename(const char *prefix,
57
+ const char *arg,
58
+ int diagnose_misspelt_rev)
59
{
60
unsigned char sha1[20];
61
unsigned mode;
62
63
+ if (!diagnose_misspelt_rev)
64
+ die("%s: no such path in the working tree.\n"
65
+ "Use '-- <path>...' to specify paths that do not exist locally.",
66
+ arg);
67
/*
68
* Saying "'(icase)foo' does not exist in the index" when the
69
* user gave us ":(icase)foo" is just stupid. A magic pathspec
86
* as true, because even if such a filename were to exist, we want
87
* it to be preceded by the "--" marker (or we want the user to
88
* use a format like "./-filename")
89
+ *
90
+ * The "diagnose_misspelt_rev" is used to provide a user-friendly
91
+ * diagnosis when dying upon finding that "name" is not a pathname.
92
+ * If set to 1, the diagnosis will try to diagnose "name" as an
93
+ * invalid object name (e.g. HEAD:foo). If set to 0, the diagnosis
94
+ * will only complain about an inexisting file.
95
+ *
96
+ * This function is typically called to check that a "file or rev"
97
+ * argument is unambiguous. In this case, the caller will want
98
+ * diagnose_misspelt_rev == 1 when verifying the first non-rev
99
+ * argument (which could have been a revision), and
100
+ * diagnose_misspelt_rev == 0 for the next ones (because we already
101
+ * saw a filename, there's not ambiguity anymore).
102
*/
84
-void verify_filename(const char *prefix, const char *arg)
103
+void verify_filename(const char *prefix,
104
+ const char *arg,
105
+ int diagnose_misspelt_rev)
106
{
107
if (*arg == '-')
108
die("bad flag '%s' used after filename", arg);
109
if (check_filename(prefix, arg))
110
return;
90
- die_verify_filename(prefix, arg);
111
+ die_verify_filename(prefix, arg, diagnose_misspelt_rev);
112
}
113
114
/*