@@ -30,6 +30,11 @@ OPTIONS
3030 Only meaningful in `--parseopt` mode. Tells the option parser to echo
3131 out the first `--` met instead of skipping it.
3232
33+ --sq-quote::
34+ Use 'git-rev-parse' in shell quoting mode (see SQ-QUOTE
35+ section below). In contrast to the `--sq` option below, this
36+ mode does only quoting. Nothing else is done to command input.
37+
3338--revs-only::
3439 Do not output flags and parameters not meant for
3540 'git-rev-list' command.
@@ -64,7 +69,8 @@ OPTIONS
6469 properly quoted for consumption by shell. Useful when
6570 you expect your parameter to contain whitespaces and
6671 newlines (e.g. when using pickaxe `-S` with
67- 'git-diff-\*').
72+ 'git-diff-\*'). In contrast to the `--sq-quote` option,
73+ the command input is still interpreted as usual.
6874
6975--not::
7076 When showing object names, prefix them with '{caret}' and
@@ -406,6 +412,33 @@ C? option C with an optional argument"
406412eval `echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`
407413------------
408414
415+ SQ-QUOTE
416+ --------
417+
418+ In `--sq-quote` mode, 'git-rev-parse' echoes on the standard output a
419+ single line suitable for `sh(1)` `eval`. This line is made by
420+ normalizing the arguments following `--sq-quote`. Nothing other than
421+ quoting the arguments is done.
422+
423+ If you want command input to still be interpreted as usual by
424+ 'git-rev-parse' before the output is shell quoted, see the `--sq`
425+ option.
426+
427+ Example
428+ ~~~~~~~
429+
430+ ------------
431+ $ cat >your-git-script.sh <<\EOF
432+ #!/bin/sh
433+ args=$(git rev-parse --sq-quote "$@") # quote user-supplied arguments
434+ command="git frotz -n24 $args" # and use it inside a handcrafted
435+ # command line
436+ eval "$command"
437+ EOF
438+
439+ $ sh your-git-script.sh "a b'c"
440+ ------------
441+
409442EXAMPLES
410443--------
411444
0 commit comments