[PATCH] Check for -amend as a common wrong usage of --amend.

Subsystems: the rest

DORMANTno replies

8 messages, 6 authors, 2016-06-15 · open the first message on its own page

[PATCH] Check for -amend as a common wrong usage of --amend.

From: Pascal Obry <hidden>
Date: 2016-06-15 22:44:08

It happens from time to time to type -amend (with a single
dash) when --amend is meant. In those case there is no mistake
and git commit all files modified with the log message set
to "end". As -amend is just doing something stupid it is
better to check for this wrong usage and give hint to the
user about the possible mistake.

Signed-off-by: Pascal Obry <redacted>
---
 parse-options.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 7a08a0c..248515d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -233,6 +233,13 @@ int parse_options(int argc, const char **argv, const struct option *options,
 			continue;
 		}
 
+		if (!strcmp(arg + 1, "amend")) {
+		        error("-amend looks suspicious, don't you meant --amend\n");
+		        args.argc--;
+		        args.argv++;
+		        break;
+		}
+
 		if (arg[1] != '-') {
 			args.opt = arg + 1;
 			do {
-- 
1.5.4.rc4.23.gcab31

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Pascal Obry <hidden>
Date: 2016-06-15 22:44:08

Typing too fast I've just made this mistake the third time today. It is 
of course easy to revert but a check seems appropriate here.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:44:08

Hi,

On Thu, 24 Jan 2008, Pascal Obry wrote:
quoted hunk
diff --git a/parse-options.c b/parse-options.c
index 7a08a0c..248515d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -233,6 +233,13 @@ int parse_options(int argc, const char **argv, const struct option *options,
 			continue;
 		}
 
+		if (!strcmp(arg + 1, "amend")) {
+		        error("-amend looks suspicious, don't you meant --amend\n");
+		        args.argc--;
+		        args.argv++;
+		        break;
+		}
+
 		if (arg[1] != '-') {
 			args.opt = arg + 1;
 			do {
That is ugly.  In a source file which is by no means specific to 
git-commit, you cannot possibly mean to check for "amend".

I don't like it,
Dscho

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Pascal Obry <hidden>
Date: 2016-06-15 22:44:08

Johannes Schindelin a écrit :
That is ugly.  In a source file which is by no means specific to 
git-commit, you cannot possibly mean to check for "amend".
Agreed :( I'll try to come with something better.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Charles Bailey <hidden>
Date: 2016-06-15 22:44:08

On Thu, Jan 24, 2008 at 07:52:26PM +0100, Pascal Obry wrote:
Johannes Schindelin a écrit :
quoted
That is ugly.  In a source file which is by no means specific to 
git-commit, you cannot possibly mean to check for "amend".
Agreed :( I'll try to come with something better.

Pascal.
Would this be better handled by a commit-msg hook.  E.g.:

test "$(cat $1)" = "end" && {
    echo >&2 Commit message is \"end\", possible mis-type of --amend
    echo >&2 Use --no-verify to really commit with this commit message
	exit 1
}

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Pascal Obry <hidden>
Date: 2016-06-15 22:44:08

Charles Bailey a écrit :
Would this be better handled by a commit-msg hook.  E.g.:
I do not agree. Why check this late as this option is boggus? And 
furthermore I do not want to have to install this commit message hook in 
all my Git repositories.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Joey Hess <hidden>
Date: 2016-06-15 22:44:08

Pascal Obry wrote:
Johannes Schindelin a écrit :
quoted
That is ugly.  In a source file which is by no means specific to  
git-commit, you cannot possibly mean to check for "amend".
Agreed :( I'll try to come with something better.
Some option parsers avoid this sort of ambiguity by not allowing short
options that take a string to be bundled in the same word with other
short options.

So, for example, git-commit -am<msg> would not be allowed, while
git-commit -a -m<msg> and perhaps git-commit -am <msg> would be allowed.

There could still be problems if there were a --mend option that could
be typoed as -mend.

I don't know enough about compatability to say if this would work for git.

-- 
see shy jo
<relurk>

Re: [PATCH] Check for -amend as a common wrong usage of --amend.

From: Jörg Sommer <hidden>
Date: 2016-06-15 22:44:08

Hi Pascal,

Pascal Obry [off-list ref] wrote:
Typing too fast I've just made this mistake the third time today. It is 
of course easy to revert but a check seems appropriate here.
Why not use an alias?

% git config --get alias.cia
commit --amend

Bye, Jörg.
-- 
Two types have compatible type if their types are the same.
[ANSI C, 6.2.7]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help