Show 76 quoted lines
> When git-revert has a file argument then redirect the user to what he
> probably meant.
>
> Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> ---
> builtin-revert.c | 24 +++++++++++++++++-------
> gitk | 2 +-
> 2 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/builtin-revert.c b/builtin-revert.c
> index 62ab1fa..9660048 100644
> --- a/builtin-revert.c
> +++ b/builtin-revert.c
> @@ -38,7 +38,7 @@ static const char *me;
>
> #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
>
> -static void parse_args(int argc, const char **argv)
> +static void parse_args(int argc, const char **argv, const char *prefix)
> {
> const char * const * usage_str =
> action == REVERT ? revert_usage : cherry_pick_usage;
> @@ -58,8 +58,18 @@ static void parse_args(int argc, const char **argv)
> usage_with_options(usage_str, options);
> arg = argv[0];
>
> - if (get_sha1(arg, sha1))
> - die ("Cannot find '%s'", arg);
> + if (get_sha1(arg, sha1)) {
> + struct stat st;
> + const char *name;
> +
> + name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
> + if (!lstat(name, &st)) {
> + die("Cannot find commit '%s', did you meant: "
> + "git checkout HEAD -- '%s'", arg, arg);
> + } else {
> + die("Cannot find commit '%s'", arg);
> + }
> + }
> commit = (struct commit *)parse_object(sha1);
> if (!commit)
> die ("Could not find %s", sha1_to_hex(sha1));
> @@ -225,7 +235,7 @@ static int merge_recursive(const char *base_sha1,
> return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD);
> }
>
> -static int revert_or_cherry_pick(int argc, const char **argv)
> +static int revert_or_cherry_pick(int argc, const char **argv, const char *prefix)
> {
> unsigned char head[20];
> struct commit *base, *next, *parent;
> @@ -237,7 +247,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
> git_config(git_default_config);
> me = action == REVERT ? "revert" : "cherry-pick";
> setenv(GIT_REFLOG_ACTION, me, 0);
> - parse_args(argc, argv);
> + parse_args(argc, argv, prefix);
>
> /* this is copied from the shell script, but it's never triggered... */
> if (action == REVERT && !no_replay)
> @@ -405,12 +415,12 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
> edit = 1;
> no_replay = 1;
> action = REVERT;
> - return revert_or_cherry_pick(argc, argv);
> + return revert_or_cherry_pick(argc, argv, prefix);
> }
>
> int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
> {
> no_replay = 0;
> action = CHERRY_PICK;
> - return revert_or_cherry_pick(argc, argv);
> + return revert_or_cherry_pick(argc, argv, prefix);
> }