Skip to content

Let 'git <command> -h' show usage without a git dir

Jonathan Nieder git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest24 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/24Retire fetch--tool helper to contrib/examplesMakefile builtin.h contrib/examples/builtin-fetch--tool.c +1 more+0 -30 replies
2/24Show usage string for 'git grep -h'builtin-grep.c+7 -00 replies
3/24Show usage string for 'git cherry -h'builtin-log.c+3 -00 replies
4/24Show usage string for 'git commit-tree -h'builtin-commit-tree.c+1 -10 replies
5/24Show usage string for 'git merge-ours -h'builtin-merge-ours.c+6 -00 replies
6/24Show usage string for 'git show-ref -h'Documentation/git-show-ref.txt builtin-show-ref.c+9 -40 replies
7/24check-ref-format: update usage stringbuiltin-check-ref-format.c+5 -11 reply
8/24Show usage string for 'git check-ref-format -h'builtin-check-ref-format.c+3 -00 replies
9/24Show usage string for 'git fast-import -h'fast-import.c+3 -00 replies
10/24Show usage string for 'git get-tar-commit-id -h'builtin-tar-tree.c+6 -00 replies
11/24Show usage string for 'git imap-send -h'imap-send.c+5 -00 replies
12/24Show usage string for 'git mailsplit -h'builtin-mailsplit.c+2 -00 replies
13/24Show usage string for 'git merge-one-file -h'git-merge-one-file.sh+12 -00 replies
14/24Show usage string for 'git rev-parse -h'builtin-rev-parse.c+10 -00 replies
15/24Show usage string for 'git show-index -h'show-index.c+5 -00 replies
16/24Show usage string for 'git unpack-file -h'unpack-file.c+1 -10 replies
17/24Show usage string for 'git stripspace -h'builtin-stripspace.c+3 -10 replies
18/24merge: do not setup worktree twicebuiltin-merge.c+0 -12 replies
19/24Let 'git http-fetch -h' show usage outside any git repositoryhttp-fetch.c+13 -80 replies
20/24http-fetch: add missing initialization of argv0_pathhttp-fetch.c+2 -03 replies
21/24Let 'git <command> -h' show usage without a git dirbuiltin-log.c builtin-mv.c builtin-read-tree.c +5 more+36 -150 replies
22/24Let usage() take a printf-style formatgit-compat-util.h usage.c+10 -61 reply
23/24merge-{recursive,subtree}: use usage() to print usagebuiltin-merge-recursive.c+1 -10 replies
24/24diff --no-index: make the usage string less scarydiff-no-index.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/24] Let 'git <command> -h' show usage without a git dir
Quoted 2 lines · Junio C Hamano

So I think the right approach is something like how you handled http-push; namely, check if the sole argument is "-h", and if so show help and exit.

I took a more aggressive approach with some commands. As long as it was obviously safe and not too complicated to implement, I let -h work wherever other options work.

Tested with

git_home=$(pwd)
while read a b
do

	cmd=${a#git-}
	test "$cmd" = "$a" && continue
	echo "$cmd"
	( cd /tmp && "$git_home/git" "$cmd" -h 2>&1 | head -1 )

done |
less

and the test suite.

Thoughts?

Jonathan Nieder (24):
Retire fetch--tool helper to contrib/examples
Show usage string for 'git grep -h'
Show usage string for 'git cherry -h'
Show usage string for 'git commit-tree -h'
Show usage string for 'git merge-ours -h'
Show usage string for 'git show-ref -h'
check-ref-format: update usage string
Show usage string for 'git check-ref-format -h' Show usage string for 'git fast-import -h'
Show usage string for 'git get-tar-commit-id -h' Show usage string for 'git imap-send -h'
Show usage string for 'git mailsplit -h'
Show usage string for 'git merge-one-file -h'
Show usage string for 'git rev-parse -h'
Show usage string for 'git show-index -h'
Show usage string for 'git unpack-file -h'
Show usage string for 'git stripspace -h'
merge: do not setup worktree twice
Let 'git http-fetch -h' show usage outside any git repository
http-fetch: add missing initialization of argv0_path Let 'git <command> -h' show usage without a git dir Let usage() take a printf-style format merge-{recursive,subtree}: use usage() to print usage diff --no-index: make the usage string less scary

 Documentation/git-show-ref.txt                     |    3 +-
 Makefile                                           |    1 -
 builtin-check-ref-format.c                         |    9 +++++++-
 builtin-commit-tree.c                              |    2 +-
 builtin-grep.c                                     |    7 ++++++
 builtin-log.c                                      |    9 ++++++++
 builtin-mailsplit.c                                |    2 +
 builtin-merge-ours.c                               |    6 +++++
 builtin-merge-recursive.c                          |    2 +-
 builtin-merge.c                                    |    1 -
 builtin-mv.c                                       |    8 +++---
 builtin-read-tree.c                                |    4 +-
 builtin-reflog.c                                   |    3 ++
 builtin-rerere.c                                   |    3 ++
 builtin-rev-parse.c                                |   10 +++++++++
 builtin-show-ref.c                                 |   10 +++++++-
 builtin-stripspace.c                               |    4 ++-
 builtin-tar-tree.c                                 |    6 +++++
 builtin.h                                          |    1 -
 .../examples/builtin-fetch--tool.c                 |    0
 diff-no-index.c                                    |    2 +-
 fast-import.c                                      |    3 ++
 git-compat-util.h                                  |    2 +-
 git-merge-one-file.sh                              |   12 ++++++++++
 git.c                                              |   22 ++++++++++---------
 http-fetch.c                                       |   21 ++++++++++++------
 imap-send.c                                        |    5 ++++
 index-pack.c                                       |    3 ++
 pack-redundant.c                                   |    3 ++
 show-index.c                                       |    5 ++++
 unpack-file.c                                      |    2 +-
 usage.c                                            |   14 ++++++++----
 32 files changed, 143 insertions(+), 42 deletions(-)
 rename builtin-fetch--tool.c => contrib/examples/builtin-fetch--tool.c (100%)