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