path: root/Documentation
diff options
Diffstat (limited to 'Documentation')
1 files changed, 74 insertions, 2 deletions
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 4758c33..329fce0 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -23,6 +23,13 @@ distinguish between them.
+ Use `git-rev-parse` in option parsing mode (see PARSEOPT section below).
+ Only meaningful in `--parseopt` mode. Tells the option parser to echo
+ out the first `--` met instead of skipping it.
Do not output flags and parameters not meant for
`git-rev-list` command.
@@ -288,10 +295,75 @@ Here are a handful examples:
C^@ I J F
F^! D G H D F
+In `--parseopt` mode, `git-rev-parse` helps massaging options to bring to shell
+scripts the same facilities C builtins have. It works as an option normalizer
+(e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
+It takes on the standard input the specification of the options to parse and
+understand, and echoes on the standard output a line suitable for `sh(1)` `eval`
+to replace the arguments with normalized ones. In case of error, it outputs
+usage on the standard error stream, and exits with code 129.
+Input Format
+`git-rev-parse --parseopt` input format is fully text based. It has two parts,
+separated by a line that contains only `--`. The lines before the separator
+(should be more than one) are used for the usage.
+The lines after the separator describe the options.
+Each line of options has this format:
+<opt_spec><arg_spec>? SP+ help LF
+ its format is the short option character, then the long option name
+ separated by a comma. Both parts are not required, though at least one
+ is necessary. `h,help`, `dry-run` and `f` are all three correct
+ `<opt_spec>`.
+ an `<arg_spec>` tells the option parser if the option has an argument
+ (`=`), an optional one (`?` though its use is discouraged) or none
+ (no `<arg_spec>` in that case).
+The remainder of the line, after stripping the spaces, is used
+as the help associated to the option.
+Blank lines are ignored, and lines that don't match this specification are used
+as option group headers (start the line with a space to create such
+lines on purpose).
+some-command [options] <args>...
+some-command does foo and bar!
+h,help show the help
+foo some nifty option --foo
+bar= some cool option --bar with an argument
+ An option group Header
+C? option C with an optional argument"
+eval `echo "$OPTS_SPEC" | git-rev-parse --parseopt -- "$@" || echo exit $?`
-Written by Linus Torvalds <> and
-Junio C Hamano <>
+Written by Linus Torvalds <> .
+Junio C Hamano <> and Pierre Habouzit <>