git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}'
@ 2015-03-10 15:38 Sundararajan R
  2015-03-10 15:38 ` [v2 PATCH 2/2] reset: add tests for git reset - Sundararajan R
  2015-03-10 17:25 ` [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}' Eric Sunshine
  0 siblings, 2 replies; 5+ messages in thread
From: Sundararajan R @ 2015-03-10 15:38 UTC (permalink / raw
  To: git; +Cc: Sundararajan R

Teaching reset the - shorthand involves checking if any file named '-' exists 
because it then becomes ambiguous as to whether the user wants to reset the
file '-' or if he wants to reset the working tree to the previous branch.

check_filename() is used to perform this check. A similar ambiguity occurs 
when the file @{-1} exits. Therefore, when the files '-' or '@{-1}' exist 
then the program dies with a message about the ambiguous argument.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Sundararajan R <dyoucme@gmail.com>
---
Have made the modifications suggest by you, Eric.
Removed the part where the user is told that he can use ./- instead.

 builtin/reset.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 4c08ddc..88ce0c5 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -192,6 +192,7 @@ static void parse_args(struct pathspec *pathspec,
 {
 	const char *rev = "HEAD";
 	unsigned char unused[20];
+	int file_named_minus = 0;
 	/*
 	 * Possible arguments are:
 	 *
@@ -205,6 +206,12 @@ static void parse_args(struct pathspec *pathspec,
 	 */
 
 	if (argv[0]) {
+		if (!strcmp(argv[0], "-") && !argv[1]) {
+			if (!check_filename(prefix, "-"))
+				argv[0] = "@{-1}";
+			else
+				file_named_minus = 1;
+		}
 		if (!strcmp(argv[0], "--")) {
 			argv++; /* reset to HEAD, possibly with paths */
 		} else if (argv[1] && !strcmp(argv[1], "--")) {
@@ -226,7 +233,13 @@ static void parse_args(struct pathspec *pathspec,
 			rev = *argv++;
 		} else {
 			/* Otherwise we treat this as a filename */
-			verify_filename(prefix, argv[0], 1);
+			if (file_named_minus) {
+				die(_("ambiguous argument '-': both revision and filename\n"
+					"Use '--' to separate paths from revisions, like this:\n"
+					"'git <command> [<revision>...] -- [<file>...]'"));
+			}
+			else
+				verify_filename(prefix, argv[0], 1);
 		}
 	}
 	*rev_ret = rev;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-10 17:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-10 15:38 [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}' Sundararajan R
2015-03-10 15:38 ` [v2 PATCH 2/2] reset: add tests for git reset - Sundararajan R
2015-03-10 17:23   ` Torsten Bögershausen
2015-03-10 17:35   ` Eric Sunshine
2015-03-10 17:25 ` [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}' Eric Sunshine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).