|
| 1 | +# Formatting context |
| 2 | + |
| 3 | +These fields are available for |
| 4 | + |
| 5 | +- version serializing |
| 6 | +- searching and replacing in files |
| 7 | +- commit messages |
| 8 | +- tag names |
| 9 | +- tag annotations |
| 10 | + |
| 11 | +## Escaped characters |
| 12 | + |
| 13 | +**`#`** The literal hash or [octothorpe](https://www.merriam-webster.com/dictionary/octothorpe) character. |
| 14 | + |
| 15 | +**`;`** The literal semicolon character. |
| 16 | + |
| 17 | + |
| 18 | +## Date and time fields |
| 19 | + |
| 20 | +**`now`** A Python datetime object representing the current local time, without a time zone reference. |
| 21 | + |
| 22 | +**`utcnow`** A Python datetime object representing the current local time in the UTC time zone. |
| 23 | + |
| 24 | +You can provide [additional formatting guidance](https://docs.python.org/3.11/library/datetime.html#strftime-and-strptime-format-codes) for datetime objects using formatting codes. Put the formatting codes after the field and a colon. For example, `{now:%Y-%m-%d}` would output the current local time as `2023-04-20`. |
| 25 | + |
| 26 | +## Source code management fields |
| 27 | + |
| 28 | +These fields will only have values if the code is in a Git or Mercurial repository. |
| 29 | + |
| 30 | +**`commit_sha`** The latest commit reference. |
| 31 | + |
| 32 | +**`distance_to_latest_tag`** The number of commits since the latest tag. |
| 33 | + |
| 34 | +**`dirty`** A boolean indicating if the current repository has pending changes. |
| 35 | + |
| 36 | +## Version fields |
| 37 | + |
| 38 | +**`current_version`** The current version serialized as a string |
| 39 | + |
| 40 | +**`current_<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `current_major`, `current_minor`, and `current_patch` available. |
| 41 | + |
| 42 | +**`new_version`** The new version serialized as a string |
| 43 | + |
| 44 | +**`new_<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `new_major`, `new_minor`, and `new_patch` available. |
| 45 | + |
| 46 | +:::{note} |
| 47 | +The following fields are only available when serializing a version. |
| 48 | +::: |
| 49 | + |
| 50 | +**`<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `major`, `minor`, and `patch` available. |
| 51 | + |
| 52 | +## Environment variables |
| 53 | + |
| 54 | +Every environment variable available at runtime is included with a `$` prefix. For example if `USER` was in the environment, `{$USER}` would render that value. |
| 55 | + |
| 56 | +If you use environment variables in your version serialization, you might want to ensure they are set by executing `export VAR=value` before running the `bump-my-version` command. |
0 commit comments