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 | b551377 | 2019-04-22 03:38:39 | [diff] [blame] | 6 | git-interpret-trailers - Add or parse structured information in commit messages |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| 10 | [verse] |
Junio C Hamano | cf9c773 | 2022-10-28 18:56:06 | [diff] [blame] | 11 | 'git interpret-trailers' [--in-place] [--trim-empty] |
Junio C Hamano | 8842ccc | 2024-03-26 00:26:23 | [diff] [blame] | 12 | [(--trailer (<key>|<key-alias>)[(=|:)<value>])...] |
Junio C Hamano | cf9c773 | 2022-10-28 18:56:06 | [diff] [blame] | 13 | [--parse] [<file>...] |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 17 | Add or parse 'trailer' lines that look similar to RFC 822 e-mail |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 18 | headers, at the end of the otherwise free-form part of a commit |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 19 | message. For example, in the following commit message |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 20 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 21 | ------------------------------------------------ |
| 22 | subject |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 23 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 25 | |
| 26 | Signed-off-by: Alice <alice@example.com> |
| 27 | Signed-off-by: Bob <bob@example.com> |
| 28 | ------------------------------------------------ |
| 29 | |
| 30 | the last two lines starting with "Signed-off-by" are trailers. |
| 31 | |
| 32 | This command reads commit messages from either the |
| 33 | <file> arguments or the standard input if no <file> is specified. |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 34 | If `--parse` is specified, the output consists of the parsed trailers |
| 35 | coming from the input, without influencing them with any command line |
| 36 | options or configuration variables. |
| 37 | |
| 38 | Otherwise, this command applies `trailer.*` configuration variables |
| 39 | (which could potentially add new trailers, as well as reposition them), |
| 40 | as well as any command line arguments that can override configuration |
| 41 | variables (such as `--trailer=...` which could also add new trailers), |
| 42 | to each input file. The result is emitted on the standard output. |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 43 | |
| 44 | This command can also operate on the output of linkgit:git-format-patch[1], |
| 45 | which is more elaborate than a plain commit message. Namely, such output |
| 46 | includes a commit message (as above), a "---" divider line, and a patch part. |
| 47 | For these inputs, the divider and patch parts are not modified by |
| 48 | this command and are emitted as is on the output, unless |
| 49 | `--no-divider` is specified. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 50 | |
| 51 | Some configuration variables control the way the `--trailer` arguments |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 52 | are applied to each input and the way any existing trailer in |
| 53 | the input is changed. They also make it possible to |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 54 | automatically add some trailers. |
| 55 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 56 | By default, a '<key>=<value>' or '<key>:<value>' argument given |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 57 | using `--trailer` will be appended after the existing trailers only if |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 58 | the last trailer has a different (<key>, <value>) pair (or if there |
| 59 | is no existing trailer). The <key> and <value> parts will be trimmed |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 60 | to remove starting and trailing whitespace, and the resulting trimmed |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 61 | <key> and <value> will appear in the output like this: |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 62 | |
| 63 | ------------------------------------------------ |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 64 | key: value |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 65 | ------------------------------------------------ |
| 66 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 67 | This means that the trimmed <key> and <value> will be separated by |
| 68 | `': '` (one colon followed by one space). |
| 69 | |
Junio C Hamano | 8842ccc | 2024-03-26 00:26:23 | [diff] [blame] | 70 | For convenience, a <key-alias> can be configured to make using `--trailer` |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 71 | shorter to type on the command line. This can be configured using the |
Junio C Hamano | 8842ccc | 2024-03-26 00:26:23 | [diff] [blame] | 72 | 'trailer.<key-alias>.key' configuration variable. The <keyAlias> must be a prefix |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 73 | of the full <key> string, although case sensitivity does not matter. For |
| 74 | example, if you have |
| 75 | |
| 76 | ------------------------------------------------ |
| 77 | trailer.sign.key "Signed-off-by: " |
| 78 | ------------------------------------------------ |
| 79 | |
| 80 | in your configuration, you only need to specify `--trailer="sign: foo"` |
| 81 | on the command line instead of `--trailer="Signed-off-by: foo"`. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 82 | |
| 83 | By default the new trailer will appear at the end of all the existing |
| 84 | trailers. If there is no existing trailer, the new trailer will appear |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 85 | at the end of the input. A blank line will be added before the new |
| 86 | trailer if there isn't one already. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 87 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 88 | Existing trailers are extracted from the input by looking for |
Junio C Hamano | 615c3b3 | 2018-02-28 23:40:27 | [diff] [blame] | 89 | a group of one or more lines that (i) is all trailers, or (ii) contains at |
Junio C Hamano | ca78549 | 2016-11-23 20:12:30 | [diff] [blame] | 90 | least one Git-generated or user-configured trailer and consists of at |
| 91 | least 25% trailers. |
Junio C Hamano | f2f28b1 | 2016-10-31 21:41:58 | [diff] [blame] | 92 | The group must be preceded by one or more empty (or whitespace-only) lines. |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 93 | The group must either be at the end of the input or be the last |
Junio C Hamano | 980e61e | 2018-09-17 22:45:52 | [diff] [blame] | 94 | non-whitespace lines before a line that starts with '---' (followed by a |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 95 | space or the end of the line). |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 96 | |
Junio C Hamano | 80d588f | 2022-09-09 22:08:29 | [diff] [blame] | 97 | When reading trailers, there can be no whitespace before or inside the |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 98 | <key>, but any number of regular space and tab characters are allowed |
| 99 | between the <key> and the separator. There can be whitespaces before, |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 100 | inside or after the <value>. The <value> may be split over multiple lines |
Junio C Hamano | 80d588f | 2022-09-09 22:08:29 | [diff] [blame] | 101 | with each subsequent line starting with at least one whitespace, like |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 102 | the "folding" in RFC 822. Example: |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 103 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 104 | ------------------------------------------------ |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 105 | key: This is a very long value, with spaces and |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 106 | newlines in it. |
| 107 | ------------------------------------------------ |
| 108 | |
| 109 | Note that trailers do not follow (nor are they intended to follow) many of the |
| 110 | rules for RFC 822 headers. For example they do not follow the encoding rule. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 111 | |
| 112 | OPTIONS |
| 113 | ------- |
Junio C Hamano | 7d09864 | 2016-01-30 00:05:21 | [diff] [blame] | 114 | --in-place:: |
| 115 | Edit the files in place. |
| 116 | |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 117 | --trim-empty:: |
| 118 | If the <value> part of any trailer contains only whitespace, |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 119 | the whole trailer will be removed from the output. |
Junio C Hamano | b0a1e83 | 2015-10-15 23:08:31 | [diff] [blame] | 120 | This applies to existing trailers as well as new trailers. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 121 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 122 | --trailer <key>[(=|:)<value>]:: |
| 123 | Specify a (<key>, <value>) pair that should be applied as a |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 124 | trailer to the inputs. See the description of this |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 125 | command. |
| 126 | |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 127 | --where <placement>:: |
| 128 | --no-where:: |
| 129 | Specify where all new trailers will be added. A setting |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 130 | provided with '--where' overrides the `trailer.where` and any |
| 131 | applicable `trailer.<keyAlias>.where` configuration variables |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 132 | and applies to all '--trailer' options until the next occurrence of |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 133 | '--where' or '--no-where'. Upon encountering '--no-where', clear the |
| 134 | effect of any previous use of '--where', such that the relevant configuration |
| 135 | variables are no longer overridden. Possible placements are `after`, |
| 136 | `before`, `end` or `start`. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 137 | |
| 138 | --if-exists <action>:: |
| 139 | --no-if-exists:: |
| 140 | Specify what action will be performed when there is already at |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 141 | least one trailer with the same <key> in the input. A setting |
| 142 | provided with '--if-exists' overrides the `trailer.ifExists` and any |
| 143 | applicable `trailer.<keyAlias>.ifExists` configuration variables |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 144 | and applies to all '--trailer' options until the next occurrence of |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 145 | '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the |
| 146 | effect of any previous use of '--if-exists, such that the relevant configuration |
| 147 | variables are no longer overridden. Possible actions are `addIfDifferent`, |
Junio C Hamano | bfd91f4 | 2018-08-17 22:21:16 | [diff] [blame] | 148 | `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 149 | |
| 150 | --if-missing <action>:: |
| 151 | --no-if-missing:: |
| 152 | Specify what action will be performed when there is no other |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 153 | trailer with the same <key> in the input. A setting |
| 154 | provided with '--if-missing' overrides the `trailer.ifMissing` and any |
| 155 | applicable `trailer.<keyAlias>.ifMissing` configuration variables |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 156 | and applies to all '--trailer' options until the next occurrence of |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 157 | '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing, |
| 158 | clear the effect of any previous use of '--if-missing, such that the relevant |
| 159 | configuration variables are no longer overridden. Possible actions are `doNothing` |
Junio C Hamano | bfd91f4 | 2018-08-17 22:21:16 | [diff] [blame] | 160 | or `add`. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 161 | |
| 162 | --only-trailers:: |
| 163 | Output only the trailers, not any other parts of the input. |
| 164 | |
| 165 | --only-input:: |
| 166 | Output only trailers that exist in the input; do not add any |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 167 | from the command-line or by applying `trailer.*` configuration |
| 168 | variables. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 169 | |
| 170 | --unfold:: |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 171 | If a trailer has a value that runs over multiple lines (aka "folded"), |
| 172 | reformat the value into a single line. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 173 | |
| 174 | --parse:: |
| 175 | A convenience alias for `--only-trailers --only-input |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 176 | --unfold`. This makes it easier to only see the trailers coming from the |
| 177 | input without influencing them with any command line options or |
| 178 | configuration variables, while also making the output machine-friendly with |
| 179 | --unfold. |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 180 | |
Junio C Hamano | 980e61e | 2018-09-17 22:45:52 | [diff] [blame] | 181 | --no-divider:: |
| 182 | Do not treat `---` as the end of the commit message. Use this |
| 183 | when you know your input contains just the commit message itself |
| 184 | (and not an email or the output of `git format-patch`). |
| 185 | |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 186 | CONFIGURATION VARIABLES |
| 187 | ----------------------- |
| 188 | |
| 189 | trailer.separators:: |
| 190 | This option tells which characters are recognized as trailer |
| 191 | separators. By default only ':' is recognized as a trailer |
| 192 | separator, except that '=' is always accepted on the command |
| 193 | line for compatibility with other git commands. |
| 194 | + |
| 195 | The first character given by this option will be the default character |
| 196 | used when another separator is not specified in the config for this |
| 197 | trailer. |
| 198 | + |
| 199 | For example, if the value for this option is "%=$", then only lines |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 200 | using the format '<key><sep><value>' with <sep> containing '%', '=' |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 201 | or '$' and then spaces will be considered trailers. And '%' will be |
| 202 | the default separator used, so by default trailers will appear like: |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 203 | '<key>% <value>' (one percent sign and one space will appear between |
| 204 | the key and the value). |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 205 | |
| 206 | trailer.where:: |
| 207 | This option tells where a new trailer will be added. |
| 208 | + |
| 209 | This can be `end`, which is the default, `start`, `after` or `before`. |
| 210 | + |
| 211 | If it is `end`, then each new trailer will appear at the end of the |
| 212 | existing trailers. |
| 213 | + |
| 214 | If it is `start`, then each new trailer will appear at the start, |
| 215 | instead of the end, of the existing trailers. |
| 216 | + |
| 217 | If it is `after`, then each new trailer will appear just after the |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 218 | last trailer with the same <key>. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 219 | + |
| 220 | If it is `before`, then each new trailer will appear just before the |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 221 | first trailer with the same <key>. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 222 | |
| 223 | trailer.ifexists:: |
| 224 | This option makes it possible to choose what action will be |
| 225 | performed when there is already at least one trailer with the |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 226 | same <key> in the input. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 227 | + |
| 228 | The valid values for this option are: `addIfDifferentNeighbor` (this |
Junio C Hamano | 222ed82 | 2017-06-02 06:24:06 | [diff] [blame] | 229 | is the default), `addIfDifferent`, `add`, `replace` or `doNothing`. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 230 | + |
| 231 | With `addIfDifferentNeighbor`, a new trailer will be added only if no |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 232 | trailer with the same (<key>, <value>) pair is above or below the line |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 233 | where the new trailer will be added. |
| 234 | + |
| 235 | With `addIfDifferent`, a new trailer will be added only if no trailer |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 236 | with the same (<key>, <value>) pair is already in the input. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 237 | + |
| 238 | With `add`, a new trailer will be added, even if some trailers with |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 239 | the same (<key>, <value>) pair are already in the input. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 240 | + |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 241 | With `replace`, an existing trailer with the same <key> will be |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 242 | deleted and the new trailer will be added. The deleted trailer will be |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 243 | the closest one (with the same <key>) to the place where the new one |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 244 | will be added. |
| 245 | + |
| 246 | With `doNothing`, nothing will be done; that is no new trailer will be |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 247 | added if there is already one with the same <key> in the input. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 248 | |
| 249 | trailer.ifmissing:: |
| 250 | This option makes it possible to choose what action will be |
| 251 | performed when there is not yet any trailer with the same |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 252 | <key> in the input. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 253 | + |
| 254 | The valid values for this option are: `add` (this is the default) and |
| 255 | `doNothing`. |
| 256 | + |
| 257 | With `add`, a new trailer will be added. |
| 258 | + |
| 259 | With `doNothing`, nothing will be done. |
| 260 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 261 | trailer.<keyAlias>.key:: |
| 262 | Defines a <keyAlias> for the <key>. The <keyAlias> must be a |
| 263 | prefix (case does not matter) of the <key>. For example, in `git |
| 264 | config trailer.ack.key "Acked-by"` the "Acked-by" is the <key> and |
| 265 | the "ack" is the <keyAlias>. This configuration allows the shorter |
| 266 | `--trailer "ack:..."` invocation on the command line using the "ack" |
| 267 | <keyAlias> instead of the longer `--trailer "Acked-by:..."`. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 268 | + |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 269 | At the end of the <key>, a separator can appear and then some |
| 270 | space characters. By default the only valid separator is ':', |
| 271 | but this can be changed using the `trailer.separators` config |
| 272 | variable. |
| 273 | + |
| 274 | If there is a separator in the key, then it overrides the default |
| 275 | separator when adding the trailer. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 276 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 277 | trailer.<keyAlias>.where:: |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 278 | This option takes the same values as the 'trailer.where' |
| 279 | configuration variable and it overrides what is specified by |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 280 | that option for trailers with the specified <keyAlias>. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 281 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 282 | trailer.<keyAlias>.ifexists:: |
Junio C Hamano | fb1fdf1 | 2017-08-27 06:14:59 | [diff] [blame] | 283 | This option takes the same values as the 'trailer.ifexists' |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 284 | configuration variable and it overrides what is specified by |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 285 | that option for trailers with the specified <keyAlias>. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 286 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 287 | trailer.<keyAlias>.ifmissing:: |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 288 | This option takes the same values as the 'trailer.ifmissing' |
| 289 | configuration variable and it overrides what is specified by |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 290 | that option for trailers with the specified <keyAlias>. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 291 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 292 | trailer.<keyAlias>.command:: |
| 293 | Deprecated in favor of 'trailer.<keyAlias>.cmd'. |
| 294 | This option behaves in the same way as 'trailer.<keyAlias>.cmd', except |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 295 | that it doesn't pass anything as argument to the specified command. |
| 296 | Instead the first occurrence of substring $ARG is replaced by the |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 297 | <value> that would be passed as argument. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 298 | + |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 299 | Note that $ARG in the user's command is |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 300 | only replaced once and that the original way of replacing $ARG is not safe. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 301 | + |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 302 | When both 'trailer.<keyAlias>.cmd' and 'trailer.<keyAlias>.command' are given |
| 303 | for the same <keyAlias>, 'trailer.<keyAlias>.cmd' is used and |
| 304 | 'trailer.<keyAlias>.command' is ignored. |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 305 | |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 306 | trailer.<keyAlias>.cmd:: |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 307 | This option can be used to specify a shell command that will be called |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 308 | once to automatically add a trailer with the specified <keyAlias>, and then |
| 309 | called each time a '--trailer <keyAlias>=<value>' argument is specified to |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 310 | modify the <value> of the trailer that this option would produce. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 311 | + |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 312 | When the specified command is first called to add a trailer |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 313 | with the specified <keyAlias>, the behavior is as if a special |
| 314 | '--trailer <keyAlias>=<value>' argument was added at the beginning |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 315 | of the "git interpret-trailers" command, where <value> |
| 316 | is taken to be the standard output of the command with any |
| 317 | leading and trailing whitespace trimmed off. |
| 318 | + |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 319 | If some '--trailer <keyAlias>=<value>' arguments are also passed |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 320 | on the command line, the command is called again once for each |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 321 | of these arguments with the same <keyAlias>. And the <value> part |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 322 | of these arguments, if any, will be passed to the command as its |
| 323 | first argument. This way the command can produce a <value> computed |
Junio C Hamano | c05b764 | 2023-10-13 22:27:26 | [diff] [blame] | 324 | from the <value> passed in the '--trailer <keyAlias>=<value>' argument. |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 325 | |
| 326 | EXAMPLES |
| 327 | -------- |
| 328 | |
| 329 | * Configure a 'sign' trailer with a 'Signed-off-by' key, and then |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 330 | add two of these trailers to a commit message file: |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 331 | + |
| 332 | ------------ |
| 333 | $ git config trailer.sign.key "Signed-off-by" |
| 334 | $ cat msg.txt |
| 335 | subject |
| 336 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 337 | body text |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 338 | $ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 339 | subject |
| 340 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 341 | body text |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 342 | |
| 343 | Signed-off-by: Alice <alice@example.com> |
| 344 | Signed-off-by: Bob <bob@example.com> |
| 345 | ------------ |
| 346 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 347 | * Use the `--in-place` option to edit a commit message file in place: |
Junio C Hamano | 7d09864 | 2016-01-30 00:05:21 | [diff] [blame] | 348 | + |
| 349 | ------------ |
| 350 | $ cat msg.txt |
| 351 | subject |
| 352 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 353 | body text |
Junio C Hamano | 7d09864 | 2016-01-30 00:05:21 | [diff] [blame] | 354 | |
| 355 | Signed-off-by: Bob <bob@example.com> |
| 356 | $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt |
| 357 | $ cat msg.txt |
| 358 | subject |
| 359 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 360 | body text |
Junio C Hamano | 7d09864 | 2016-01-30 00:05:21 | [diff] [blame] | 361 | |
| 362 | Signed-off-by: Bob <bob@example.com> |
| 363 | Acked-by: Alice <alice@example.com> |
| 364 | ------------ |
| 365 | |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 366 | * Extract the last commit as a patch, and add a 'Cc' and a |
| 367 | 'Reviewed-by' trailer to it: |
| 368 | + |
| 369 | ------------ |
| 370 | $ git format-patch -1 |
| 371 | 0001-foo.patch |
| 372 | $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch |
| 373 | ------------ |
| 374 | |
| 375 | * Configure a 'sign' trailer with a command to automatically add a |
| 376 | 'Signed-off-by: ' with the author information only if there is no |
| 377 | 'Signed-off-by: ' already, and show how it works: |
| 378 | + |
| 379 | ------------ |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 380 | $ cat msg1.txt |
| 381 | subject |
| 382 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 383 | body text |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 384 | $ git config trailer.sign.key "Signed-off-by: " |
| 385 | $ git config trailer.sign.ifmissing add |
| 386 | $ git config trailer.sign.ifexists doNothing |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 387 | $ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"' |
| 388 | $ git interpret-trailers --trailer sign <msg1.txt |
| 389 | subject |
| 390 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 391 | body text |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 392 | |
| 393 | Signed-off-by: Bob <bob@example.com> |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 394 | $ cat msg2.txt |
| 395 | subject |
| 396 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 397 | body text |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 398 | |
| 399 | Signed-off-by: Alice <alice@example.com> |
| 400 | $ git interpret-trailers --trailer sign <msg2.txt |
| 401 | subject |
| 402 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 403 | body text |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 404 | |
| 405 | Signed-off-by: Alice <alice@example.com> |
| 406 | ------------ |
| 407 | |
| 408 | * Configure a 'fix' trailer with a key that contains a '#' and no |
| 409 | space after this character, and show how it works: |
| 410 | + |
| 411 | ------------ |
| 412 | $ git config trailer.separators ":#" |
| 413 | $ git config trailer.fix.key "Fix #" |
| 414 | $ echo "subject" | git interpret-trailers --trailer fix=42 |
| 415 | subject |
| 416 | |
| 417 | Fix #42 |
| 418 | ------------ |
| 419 | |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 420 | * Configure a 'help' trailer with a cmd use a script `glog-find-author` |
| 421 | which search specified author identity from git log in git repository |
| 422 | and show how it works: |
| 423 | + |
| 424 | ------------ |
| 425 | $ cat ~/bin/glog-find-author |
| 426 | #!/bin/sh |
| 427 | test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 428 | $ cat msg.txt |
| 429 | subject |
| 430 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 431 | body text |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 432 | $ git config trailer.help.key "Helped-by: " |
| 433 | $ git config trailer.help.ifExists "addIfDifferentNeighbor" |
| 434 | $ git config trailer.help.cmd "~/bin/glog-find-author" |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 435 | $ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 436 | subject |
| 437 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 438 | body text |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 439 | |
| 440 | Helped-by: Junio C Hamano <gitster@pobox.com> |
| 441 | Helped-by: Christian Couder <christian.couder@gmail.com> |
| 442 | ------------ |
| 443 | |
| 444 | * Configure a 'ref' trailer with a cmd use a script `glog-grep` |
| 445 | to grep last relevant commit from git log in the git repository |
| 446 | and show how it works: |
| 447 | + |
| 448 | ------------ |
| 449 | $ cat ~/bin/glog-grep |
| 450 | #!/bin/sh |
| 451 | test -n "$1" && git log --grep "$1" --pretty=reference -1 || true |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 452 | $ cat msg.txt |
| 453 | subject |
| 454 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 455 | body text |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 456 | $ git config trailer.ref.key "Reference-to: " |
| 457 | $ git config trailer.ref.ifExists "replace" |
| 458 | $ git config trailer.ref.cmd "~/bin/glog-grep" |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 459 | $ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 460 | subject |
| 461 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 462 | body text |
Junio C Hamano | 51a55bc | 2021-05-12 05:22:19 | [diff] [blame] | 463 | |
| 464 | Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07) |
| 465 | ------------ |
| 466 | |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 467 | * Configure a 'see' trailer with a command to show the subject of a |
| 468 | commit that is related, and show how it works: |
| 469 | + |
| 470 | ------------ |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 471 | $ cat msg.txt |
| 472 | subject |
| 473 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 474 | body text |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 475 | |
| 476 | see: HEAD~2 |
| 477 | $ cat ~/bin/glog-ref |
| 478 | #!/bin/sh |
| 479 | git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 480 | $ git config trailer.see.key "See-also: " |
| 481 | $ git config trailer.see.ifExists "replace" |
| 482 | $ git config trailer.see.ifMissing "doNothing" |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 483 | $ git config trailer.see.cmd "glog-ref" |
| 484 | $ git interpret-trailers --trailer=see <msg.txt |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 485 | subject |
| 486 | |
Junio C Hamano | 9469c13 | 2023-06-23 20:26:29 | [diff] [blame] | 487 | body text |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 488 | |
| 489 | See-also: fe3187489d69c4 (subject of related commit) |
| 490 | ------------ |
| 491 | |
| 492 | * Configure a commit template with some trailers with empty values |
| 493 | (using sed to show and keep the trailing spaces at the end of the |
| 494 | trailers), then configure a commit-msg hook that uses |
| 495 | 'git interpret-trailers' to remove trailers with empty values and |
| 496 | to add a 'git-version' trailer: |
| 497 | + |
| 498 | ------------ |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 499 | $ cat temp.txt |
| 500 | ***subject*** |
| 501 | |
| 502 | ***message*** |
| 503 | |
| 504 | Fixes: Z |
| 505 | Cc: Z |
| 506 | Reviewed-by: Z |
| 507 | Signed-off-by: Z |
| 508 | $ sed -e 's/ Z$/ /' temp.txt > commit_template.txt |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 509 | $ git config commit.template commit_template.txt |
Junio C Hamano | d37473e | 2023-05-15 23:04:43 | [diff] [blame] | 510 | $ cat .git/hooks/commit-msg |
| 511 | #!/bin/sh |
| 512 | git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new" |
| 513 | mv "\$1.new" "\$1" |
Junio C Hamano | 4c43d65 | 2014-10-20 21:14:29 | [diff] [blame] | 514 | $ chmod +x .git/hooks/commit-msg |
| 515 | ------------ |
| 516 | |
| 517 | SEE ALSO |
| 518 | -------- |
| 519 | linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1] |
| 520 | |
| 521 | GIT |
| 522 | --- |
| 523 | Part of the linkgit:git[1] suite |