git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Adding - shorthand for @{-1} in RESET command
@ 2015-03-09 20:46 Sundararajan R
  2015-03-09 20:46 ` [PATCH 2/2] Added tests for git reset - Sundararajan R
  2015-03-10  6:54 ` [PATCH 1/2] Adding - shorthand for @{-1} in RESET command Eric Sunshine
  0 siblings, 2 replies; 7+ messages in thread
From: Sundararajan R @ 2015-03-09 20:46 UTC (permalink / raw)
  To: git; +Cc: Sundararajan R

Please give feedback and suggest things I may have missed out on. 
I hope I have incorporated all the suggestions.

Signed-off-by: Sundararajan R <dyoucme@gmail.com>
Thanks-to: Junio C Hamano
---
I have attempted to resolve the ambiguity when there exists a file named -
by communicating to the user that he/she can use ./- when he/she wants to refer
to the - file. I perform this check using the check_filename() function.

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

diff --git a/builtin/reset.c b/builtin/reset.c
index 4c08ddc..2bdd5cd 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,14 @@ 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 ./- for file named -\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] 7+ messages in thread

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-09 20:46 [PATCH 1/2] Adding - shorthand for @{-1} in RESET command Sundararajan R
2015-03-09 20:46 ` [PATCH 2/2] Added tests for git reset - Sundararajan R
2015-03-10  5:48   ` Torsten Bögershausen
2015-03-10  7:49   ` Eric Sunshine
2015-03-10 17:36     ` Junio C Hamano
2015-03-10  6:54 ` [PATCH 1/2] Adding - shorthand for @{-1} in RESET command Eric Sunshine
2015-03-10 17:43   ` Junio C Hamano

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).