git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: gitster@pobox.com
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH] git-revert is one of the most misunderstood command in git, help users out.
Date: Mon,  5 Nov 2007 20:01:41 +0100	[thread overview]
Message-ID: <1194289301-7800-1-git-send-email-madcoder@debian.org> (raw)

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);
 }
diff --git a/gitk b/gitk
index 1da0b0a..ab8bab2 100755
--- a/gitk
+++ b/gitk
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Tcl ignores the next line -*- tcl -*- \
-exec wish "$0" -- "$@"
+exec wish8.5 "$0" -- "$@"
 
 # Copyright (C) 2005-2006 Paul Mackerras.  All rights reserved.
 # This program is free software; it may be used, copied, modified
-- 
1.5.3.5.1541.gd2b5c-dirty


             reply	other threads:[~2007-11-05 19:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-05 19:01 Pierre Habouzit [this message]
2007-11-05 19:04 ` [PATCH] git-revert is one of the most misunderstood command in git, help users out Pierre Habouzit
2007-11-05 19:05   ` J. Bruce Fields
2007-11-05 19:10     ` Pierre Habouzit
2007-11-05 19:28 ` Steven Grimm
2007-11-05 19:50   ` Pierre Habouzit
2007-11-05 21:54   ` Alejandro Martinez Ruiz
2007-11-05 22:06     ` David Kastrup
2007-11-05 23:41       ` Alejandro Martinez Ruiz
2007-11-05 22:21   ` Junio C Hamano
2007-11-05 23:40     ` Johannes Schindelin
2007-11-06  0:08       ` Pierre Habouzit
2007-11-06  2:51       ` Junio C Hamano
2007-11-06  3:18         ` Johannes Schindelin
2007-11-06  4:54           ` Junio C Hamano
2007-11-06  8:49             ` Pierre Habouzit
2007-11-06  9:29               ` Mike Hommey
2007-11-06  9:37                 ` Pierre Habouzit
2007-11-06 12:32             ` Johannes Schindelin
2007-11-06 18:06               ` Junio C Hamano
2007-11-06 18:27                 ` Johannes Schindelin
2007-11-06 19:39                   ` Pierre Habouzit
2007-11-06 19:42                     ` Junio C Hamano
2007-11-06 22:21                       ` Johannes Schindelin
2007-11-06 20:06               ` Robin Rosenberg
2007-11-06 20:13                 ` Mike Hommey
2007-11-06 21:21                   ` Robin Rosenberg
2007-11-06 22:25                     ` Johannes Schindelin
2007-11-07  8:16                       ` Mike Hommey
2007-11-07 11:08                         ` Johannes Schindelin
2007-11-07 19:32                           ` Robin Rosenberg
2007-11-07 20:01                             ` Jakub Narebski
2007-11-07  9:03                       ` David Kastrup
2007-11-06 11:08         ` Junio C Hamano
2007-11-06 11:51           ` Johannes Sixt
2007-11-06 12:16             ` Johannes Schindelin
2007-11-06 12:25           ` Johannes Schindelin
2007-11-06 12:48             ` Pierre Habouzit
2007-11-06 17:43               ` Wincent Colaiuta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1194289301-7800-1-git-send-email-madcoder@debian.org \
    --to=madcoder@debian.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).