Documentation / git-interpret-trailers.txton commit interpret-trailers: add options for actions (0ea5292)
   1git-interpret-trailers(1)
   2=========================
   3
   4NAME
   5----
   6git-interpret-trailers - help add structured information into commit messages
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git interpret-trailers' [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]
  12
  13DESCRIPTION
  14-----------
  15Help adding 'trailers' lines, that look similar to RFC 822 e-mail
  16headers, at the end of the otherwise free-form part of a commit
  17message.
  18
  19This command reads some patches or commit messages from either the
  20<file> arguments or the standard input if no <file> is specified. Then
  21this command applies the arguments passed using the `--trailer`
  22option, if any, to the commit message part of each input file. The
  23result is emitted on the standard output.
  24
  25Some configuration variables control the way the `--trailer` arguments
  26are applied to each commit message and the way any existing trailer in
  27the commit message is changed. They also make it possible to
  28automatically add some trailers.
  29
  30By default, a '<token>=<value>' or '<token>:<value>' argument given
  31using `--trailer` will be appended after the existing trailers only if
  32the last trailer has a different (<token>, <value>) pair (or if there
  33is no existing trailer). The <token> and <value> parts will be trimmed
  34to remove starting and trailing whitespace, and the resulting trimmed
  35<token> and <value> will appear in the message like this:
  36
  37------------------------------------------------
  38token: value
  39------------------------------------------------
  40
  41This means that the trimmed <token> and <value> will be separated by
  42`': '` (one colon followed by one space).
  43
  44By default the new trailer will appear at the end of all the existing
  45trailers. If there is no existing trailer, the new trailer will appear
  46after the commit message part of the output, and, if there is no line
  47with only spaces at the end of the commit message part, one blank line
  48will be added before the new trailer.
  49
  50Existing trailers are extracted from the input message by looking for
  51a group of one or more lines that (i) are all trailers, or (ii) contains at
  52least one Git-generated or user-configured trailer and consists of at
  53least 25% trailers.
  54The group must be preceded by one or more empty (or whitespace-only) lines.
  55The group must either be at the end of the message or be the last
  56non-whitespace lines before a line that starts with '---'. Such three
  57minus signs start the patch part of the message.
  58
  59When reading trailers, there can be whitespaces after the
  60token, the separator and the value. There can also be whitespaces
  61inside the token and the value. The value may be split over multiple lines with
  62each subsequent line starting with whitespace, like the "folding" in RFC 822.
  63
  64Note that 'trailers' do not follow and are not intended to follow many
  65rules for RFC 822 headers. For example they do not follow
  66the encoding rules and probably many other rules.
  67
  68OPTIONS
  69-------
  70--in-place::
  71        Edit the files in place.
  72
  73--trim-empty::
  74        If the <value> part of any trailer contains only whitespace,
  75        the whole trailer will be removed from the resulting message.
  76        This applies to existing trailers as well as new trailers.
  77
  78--trailer <token>[(=|:)<value>]::
  79        Specify a (<token>, <value>) pair that should be applied as a
  80        trailer to the input messages. See the description of this
  81        command.
  82
  83--where <placement>::
  84--no-where::
  85        Specify where all new trailers will be added.  A setting
  86        provided with '--where' overrides all configuration variables
  87        and applies to all '--trailer' options until the next occurrence of
  88        '--where' or '--no-where'.
  89
  90--if-exists <action>::
  91--no-if-exists::
  92        Specify what action will be performed when there is already at
  93        least one trailer with the same <token> in the message.  A setting
  94        provided with '--if-exists' overrides all configuration variables
  95        and applies to all '--trailer' options until the next occurrence of
  96        '--if-exists' or '--no-if-exists'.
  97
  98--if-missing <action>::
  99--no-if-missing::
 100        Specify what action will be performed when there is no other
 101        trailer with the same <token> in the message.  A setting
 102        provided with '--if-missing' overrides all configuration variables
 103        and applies to all '--trailer' options until the next occurrence of
 104        '--if-missing' or '--no-if-missing'.
 105
 106CONFIGURATION VARIABLES
 107-----------------------
 108
 109trailer.separators::
 110        This option tells which characters are recognized as trailer
 111        separators. By default only ':' is recognized as a trailer
 112        separator, except that '=' is always accepted on the command
 113        line for compatibility with other git commands.
 114+
 115The first character given by this option will be the default character
 116used when another separator is not specified in the config for this
 117trailer.
 118+
 119For example, if the value for this option is "%=$", then only lines
 120using the format '<token><sep><value>' with <sep> containing '%', '='
 121or '$' and then spaces will be considered trailers. And '%' will be
 122the default separator used, so by default trailers will appear like:
 123'<token>% <value>' (one percent sign and one space will appear between
 124the token and the value).
 125
 126trailer.where::
 127        This option tells where a new trailer will be added.
 128+
 129This can be `end`, which is the default, `start`, `after` or `before`.
 130+
 131If it is `end`, then each new trailer will appear at the end of the
 132existing trailers.
 133+
 134If it is `start`, then each new trailer will appear at the start,
 135instead of the end, of the existing trailers.
 136+
 137If it is `after`, then each new trailer will appear just after the
 138last trailer with the same <token>.
 139+
 140If it is `before`, then each new trailer will appear just before the
 141first trailer with the same <token>.
 142
 143trailer.ifexists::
 144        This option makes it possible to choose what action will be
 145        performed when there is already at least one trailer with the
 146        same <token> in the message.
 147+
 148The valid values for this option are: `addIfDifferentNeighbor` (this
 149is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
 150+
 151With `addIfDifferentNeighbor`, a new trailer will be added only if no
 152trailer with the same (<token>, <value>) pair is above or below the line
 153where the new trailer will be added.
 154+
 155With `addIfDifferent`, a new trailer will be added only if no trailer
 156with the same (<token>, <value>) pair is already in the message.
 157+
 158With `add`, a new trailer will be added, even if some trailers with
 159the same (<token>, <value>) pair are already in the message.
 160+
 161With `replace`, an existing trailer with the same <token> will be
 162deleted and the new trailer will be added. The deleted trailer will be
 163the closest one (with the same <token>) to the place where the new one
 164will be added.
 165+
 166With `doNothing`, nothing will be done; that is no new trailer will be
 167added if there is already one with the same <token> in the message.
 168
 169trailer.ifmissing::
 170        This option makes it possible to choose what action will be
 171        performed when there is not yet any trailer with the same
 172        <token> in the message.
 173+
 174The valid values for this option are: `add` (this is the default) and
 175`doNothing`.
 176+
 177With `add`, a new trailer will be added.
 178+
 179With `doNothing`, nothing will be done.
 180
 181trailer.<token>.key::
 182        This `key` will be used instead of <token> in the trailer. At
 183        the end of this key, a separator can appear and then some
 184        space characters. By default the only valid separator is ':',
 185        but this can be changed using the `trailer.separators` config
 186        variable.
 187+
 188If there is a separator, then the key will be used instead of both the
 189<token> and the default separator when adding the trailer.
 190
 191trailer.<token>.where::
 192        This option takes the same values as the 'trailer.where'
 193        configuration variable and it overrides what is specified by
 194        that option for trailers with the specified <token>.
 195
 196trailer.<token>.ifexist::
 197        This option takes the same values as the 'trailer.ifexist'
 198        configuration variable and it overrides what is specified by
 199        that option for trailers with the specified <token>.
 200
 201trailer.<token>.ifmissing::
 202        This option takes the same values as the 'trailer.ifmissing'
 203        configuration variable and it overrides what is specified by
 204        that option for trailers with the specified <token>.
 205
 206trailer.<token>.command::
 207        This option can be used to specify a shell command that will
 208        be called to automatically add or modify a trailer with the
 209        specified <token>.
 210+
 211When this option is specified, the behavior is as if a special
 212'<token>=<value>' argument were added at the beginning of the command
 213line, where <value> is taken to be the standard output of the
 214specified command with any leading and trailing whitespace trimmed
 215off.
 216+
 217If the command contains the `$ARG` string, this string will be
 218replaced with the <value> part of an existing trailer with the same
 219<token>, if any, before the command is launched.
 220+
 221If some '<token>=<value>' arguments are also passed on the command
 222line, when a 'trailer.<token>.command' is configured, the command will
 223also be executed for each of these arguments. And the <value> part of
 224these arguments, if any, will be used to replace the `$ARG` string in
 225the command.
 226
 227EXAMPLES
 228--------
 229
 230* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
 231  add two of these trailers to a message:
 232+
 233------------
 234$ git config trailer.sign.key "Signed-off-by"
 235$ cat msg.txt
 236subject
 237
 238message
 239$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
 240subject
 241
 242message
 243
 244Signed-off-by: Alice <alice@example.com>
 245Signed-off-by: Bob <bob@example.com>
 246------------
 247
 248* Use the `--in-place` option to edit a message file in place:
 249+
 250------------
 251$ cat msg.txt
 252subject
 253
 254message
 255
 256Signed-off-by: Bob <bob@example.com>
 257$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
 258$ cat msg.txt
 259subject
 260
 261message
 262
 263Signed-off-by: Bob <bob@example.com>
 264Acked-by: Alice <alice@example.com>
 265------------
 266
 267* Extract the last commit as a patch, and add a 'Cc' and a
 268  'Reviewed-by' trailer to it:
 269+
 270------------
 271$ git format-patch -1
 2720001-foo.patch
 273$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
 274------------
 275
 276* Configure a 'sign' trailer with a command to automatically add a
 277  'Signed-off-by: ' with the author information only if there is no
 278  'Signed-off-by: ' already, and show how it works:
 279+
 280------------
 281$ git config trailer.sign.key "Signed-off-by: "
 282$ git config trailer.sign.ifmissing add
 283$ git config trailer.sign.ifexists doNothing
 284$ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
 285$ git interpret-trailers <<EOF
 286> EOF
 287
 288Signed-off-by: Bob <bob@example.com>
 289$ git interpret-trailers <<EOF
 290> Signed-off-by: Alice <alice@example.com>
 291> EOF
 292
 293Signed-off-by: Alice <alice@example.com>
 294------------
 295
 296* Configure a 'fix' trailer with a key that contains a '#' and no
 297  space after this character, and show how it works:
 298+
 299------------
 300$ git config trailer.separators ":#"
 301$ git config trailer.fix.key "Fix #"
 302$ echo "subject" | git interpret-trailers --trailer fix=42
 303subject
 304
 305Fix #42
 306------------
 307
 308* Configure a 'see' trailer with a command to show the subject of a
 309  commit that is related, and show how it works:
 310+
 311------------
 312$ git config trailer.see.key "See-also: "
 313$ git config trailer.see.ifExists "replace"
 314$ git config trailer.see.ifMissing "doNothing"
 315$ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
 316$ git interpret-trailers <<EOF
 317> subject
 318> 
 319> message
 320> 
 321> see: HEAD~2
 322> EOF
 323subject
 324
 325message
 326
 327See-also: fe3187489d69c4 (subject of related commit)
 328------------
 329
 330* Configure a commit template with some trailers with empty values
 331  (using sed to show and keep the trailing spaces at the end of the
 332  trailers), then configure a commit-msg hook that uses
 333  'git interpret-trailers' to remove trailers with empty values and
 334  to add a 'git-version' trailer:
 335+
 336------------
 337$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
 338> ***subject***
 339> 
 340> ***message***
 341> 
 342> Fixes: Z
 343> Cc: Z
 344> Reviewed-by: Z
 345> Signed-off-by: Z
 346> EOF
 347$ git config commit.template commit_template.txt
 348$ cat >.git/hooks/commit-msg <<EOF
 349> #!/bin/sh
 350> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
 351> mv "\$1.new" "\$1"
 352> EOF
 353$ chmod +x .git/hooks/commit-msg
 354------------
 355
 356SEE ALSO
 357--------
 358linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
 359
 360GIT
 361---
 362Part of the linkgit:git[1] suite