public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH] Allow 'git cmd -h' outside of repository
@ 2008-08-28 21:28 SZEDER Gábor
  2008-08-29 11:35 ` Johannes Schindelin
  0 siblings, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2008-08-28 21:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

Printing usage strings of git commands should obviously not depend on
the command being run inside a git repository.  However, in case of a
command requiring a repository, the command line options are parsed only
after it is ensured that the command was started inside a repository,
resulting in a 'fatal: Not a git repository' if 'git cmd -h' wasn't
executed inside a repository.

To get around this issue, we will check early for the presence of '-h'
option, and skip ensuring that the command is run inside a repository.

Signed-off-by: SZEDER Gábor <szeder@ira•uka.de>
---
 git.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/git.c b/git.c
index 37b1d76..af53472 100644
--- a/git.c
+++ b/git.c
@@ -380,6 +380,10 @@ static void handle_internal_command(int argc, const char **argv)
 		struct cmd_struct *p = commands+i;
 		if (strcmp(p->cmd, cmd))
 			continue;
+		/* Don't require repository if only usage string is requested */
+		if (argc > 1 && !strcmp(argv[1], "-h")) {
+			p->option = 0;
+		}
 		exit(run_command(p, argc, argv));
 	}
 }
-- 
1.6.0.1.133.g10dd.dirty

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

* Re: [PATCH] Allow 'git cmd -h' outside of repository
  2008-08-28 21:28 [PATCH] Allow 'git cmd -h' outside of repository SZEDER Gábor
@ 2008-08-29 11:35 ` Johannes Schindelin
  2008-08-29 11:44   ` Nguyen Thai Ngoc Duy
  2008-08-29 11:52   ` SZEDER Gábor
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Schindelin @ 2008-08-29 11:35 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Junio C Hamano, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 896 bytes --]

Hi,

On Thu, 28 Aug 2008, SZEDER Gábor wrote:

> Printing usage strings of git commands should obviously not depend on 
> the command being run inside a git repository.  However, in case of a 
> command requiring a repository, the command line options are parsed only 
> after it is ensured that the command was started inside a repository, 
> resulting in a 'fatal: Not a git repository' if 'git cmd -h' wasn't 
> executed inside a repository.
> 
> To get around this issue, we will check early for the presence of '-h'
> option, and skip ensuring that the command is run inside a repository.

You miss the fact that "git grep -h" does not mean "show usage".  Oh, and 
"git ls-remote -h" neither.  Three times's a charm: "git show-ref -h" does 
not show the help either.

I am also not quite certain if we should not just tout "git help <cmd>" as 
the official way to request help.

Ciao,
Dscho

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

* Re: [PATCH] Allow 'git cmd -h' outside of repository
  2008-08-29 11:35 ` Johannes Schindelin
@ 2008-08-29 11:44   ` Nguyen Thai Ngoc Duy
  2008-08-29 11:52   ` SZEDER Gábor
  1 sibling, 0 replies; 4+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2008-08-29 11:44 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: SZEDER Gábor, Junio C Hamano, git

On 8/29/08, Johannes Schindelin <Johannes.Schindelin@gmx•de> wrote:
> Hi,
>
>
>  On Thu, 28 Aug 2008, SZEDER Gábor wrote:
>
>  > Printing usage strings of git commands should obviously not depend on
>  > the command being run inside a git repository.  However, in case of a
>  > command requiring a repository, the command line options are parsed only
>  > after it is ensured that the command was started inside a repository,
>  > resulting in a 'fatal: Not a git repository' if 'git cmd -h' wasn't
>  > executed inside a repository.
>  >
>  > To get around this issue, we will check early for the presence of '-h'
>  > option, and skip ensuring that the command is run inside a repository.
>
>
> You miss the fact that "git grep -h" does not mean "show usage".  Oh, and
>  "git ls-remote -h" neither.  Three times's a charm: "git show-ref -h" does
>  not show the help either.
>
>  I am also not quite certain if we should not just tout "git help <cmd>" as
>  the official way to request help.

No we should not (at least to me), usage strings are shorter and don't
require man.  As for allowing "git cmd -h" outside repository, I think
Jeff's idea of refactoring setup procedure, setting up if possible but
not barfing, would solve it.
-- 
Duy

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

* Re: [PATCH] Allow 'git cmd -h' outside of repository
  2008-08-29 11:35 ` Johannes Schindelin
  2008-08-29 11:44   ` Nguyen Thai Ngoc Duy
@ 2008-08-29 11:52   ` SZEDER Gábor
  1 sibling, 0 replies; 4+ messages in thread
From: SZEDER Gábor @ 2008-08-29 11:52 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

On Fri, Aug 29, 2008 at 01:35:02PM +0200, Johannes Schindelin wrote:
> You miss the fact that "git grep -h" does not mean "show usage".  Oh, and 
> "git ls-remote -h" neither.  Three times's a charm: "git show-ref -h" does 
> not show the help either.
you are right with grep and show-ref.  However, ls-remote does not
require a repository, so it would not be affected by this patch.

> I am also not quite certain if we should not just tout "git help <cmd>" as 
> the official way to request help.
Well, I would prefer to keep the short usage.

But anyway, having this inconsistency with the -h option across git
commands is bad.

Regards,
Gábor

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

end of thread, other threads:[~2008-08-29 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-28 21:28 [PATCH] Allow 'git cmd -h' outside of repository SZEDER Gábor
2008-08-29 11:35 ` Johannes Schindelin
2008-08-29 11:44   ` Nguyen Thai Ngoc Duy
2008-08-29 11:52   ` SZEDER Gábor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox