Skip to content

Commit 7dda220

Browse files
authored
Merge pull request #47 from lubomir/commit-options
Allow arbitrary arguments to commit command
2 parents c8678da + e5fe4f7 commit 7dda220

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ General configuration is grouped in a `[bumpversion]` section.
195195
Also available as command-line flag `--message`. Example usage:
196196
`bump2version --message '[{now:%Y-%m-%d}] Jenkins Build {$BUILD_NUMBER}: {new_version}' patch`)
197197

198+
#### `commit_args =`
199+
_**[optional**_<br />
200+
**default:** empty
201+
202+
Extra arguments to pass to commit command. Only valid when using `--commit` /
203+
`commit = True`.
204+
205+
This is for example useful to add `-s` to generate `Signed-off-by:` line in
206+
the commit message.
207+
208+
Multiple arguments can be specified on separate lines.
209+
210+
Also available as command-line flag `--commit-args`, in which case only one
211+
argument can be specified.
212+
198213

199214
### Configuration file -- Part specific configuration
200215

bumpversion/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ def _parse_arguments_phase_3(remaining_argv, positionals, defaults, parser2):
534534
"message", "Bump version: {current_version} → {new_version}"
535535
),
536536
)
537+
parser3.add_argument(
538+
"--commit-args",
539+
metavar="COMMIT_ARGS",
540+
help="Extra arguments to commit command",
541+
default=defaults.get("commit_args", ""),
542+
)
537543
file_names = []
538544
if "files" in defaults:
539545
assert defaults["files"] is not None
@@ -670,7 +676,11 @@ def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, c
670676
commit_message,
671677
)
672678
if do_commit:
673-
vcs.commit(message=commit_message, context=context)
679+
vcs.commit(
680+
message=commit_message,
681+
context=context,
682+
extra_args=[arg.strip() for arg in args.commit_args.splitlines()],
683+
)
674684
return context
675685

676686

bumpversion/vcs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ class BaseVCS(object):
2424
_COMMIT_COMMAND = None
2525

2626
@classmethod
27-
def commit(cls, message, context):
27+
def commit(cls, message, context, extra_args=None):
28+
extra_args = extra_args or []
2829
with NamedTemporaryFile("wb", delete=False) as f:
2930
f.write(message.encode("utf-8"))
3031
env = os.environ.copy()
3132
env[str("HGENCODING")] = str("utf-8")
3233
for key in ("current_version", "new_version"):
3334
env[str("BUMPVERSION_" + key.upper())] = str(context[key])
3435
try:
35-
subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=env)
36+
subprocess.check_output(
37+
cls._COMMIT_COMMAND + [f.name] + extra_args, env=env
38+
)
3639
except subprocess.CalledProcessError as exc:
3740
err_msg = "Failed to run {}: return code {}, output: {}".format(
3841
exc.cmd, exc.returncode, exc.output

0 commit comments

Comments
 (0)