Skip to content

fix(#271): add annotated_tag option to bump #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Fix

- **#271**: add annotated_tag option to bump

## v2.4.0 (2020-09-18)

### Feat
Expand Down Expand Up @@ -97,17 +103,17 @@
### Fix

- **commands/bump**: use `return_code` in commands used by bump
- **commands/commit**: use return_code to raise commit error, not stderr

### Refactor

- **cmd**: add return code to Command

## v1.23.2 (2020-07-25)

### Fix

- **bump**: add changelog file into stage when running `cz bump --changelog`
- **commands/commit**: use return_code to raise commit error, not stderr

### Refactor

- **cmd**: add return code to Command

## v1.23.1 (2020-07-14)

Expand All @@ -124,17 +130,20 @@
- **commands/init**: add test case and remove unaccessible code
- **exception**: move output message related to exception into exception
- **exception**: implement message handling mechanism for CommitizenException
- **cli**: do not show traceback if the raised exception is CommitizenException
- introduce DryRunExit, ExpectedExit, NoCommandFoundError, InvalidCommandArgumentError
- use custom exception for error handling
- **error_codes**: remove unused NO_COMMIT_MSG error code

### Feat

- **cli**: enable displaying all traceback for CommitizenException when --debug flag is used

## v1.22.3 (2020-06-10)

### Refactor

- **cli**: do not show traceback if the raised exception is CommitizenException
- introduce DryRunExit, ExpectedExit, NoCommandFoundError, InvalidCommandArgumentError
- use custom exception for error handling
- **error_codes**: remove unused NO_COMMIT_MSG error code

## v1.22.2 (2020-05-29)

### Fix
Expand Down
5 changes: 5 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
),
"action": "store_true",
},
{
"name": ["--annotated-tag", "-at"],
"help": "create annotated tag instead of lightweight one",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change the help message to create an annotated tag (by default, commitizen creates lightweight tag)

"action": "store_true",
},
],
},
{
Expand Down
14 changes: 12 additions & 2 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def __init__(self, config: BaseConfig, arguments: dict):
**config.settings,
**{
key: arguments[key]
for key in ["tag_format", "prerelease", "increment", "bump_message"]
for key in [
"tag_format",
"prerelease",
"increment",
"bump_message",
"annotated_tag",
]
if arguments[key] is not None
},
}
Expand Down Expand Up @@ -157,7 +163,11 @@ def __call__(self): # noqa: C901
c = git.commit(message, args=self._get_commit_args())
if c.return_code != 0:
raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"')
c = git.tag(new_tag_version)
c = git.tag(
new_tag_version,
annotated=self.bump_settings.get("annotated_tag", False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to enhance readbility, I would suggest make self.bump_settings.get("annotated_tag", False) or or bool(self.config.settings.get("annotated_tag", False)) a variable. I read this line for a few times to understand

or bool(self.config.settings.get("annotated_tag", False)),
)
if c.return_code != 0:
raise BumpTagFailedError(c.err)
out.success("Done!")
Expand Down
4 changes: 2 additions & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __repr__(self):
return f"GitTag('{self.name}', '{self.rev}', '{self.date}')"


def tag(tag: str):
c = cmd.run(f"git tag {tag}")
def tag(tag: str, annotated: bool = False):
c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}")
return c


Expand Down
31 changes: 19 additions & 12 deletions docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,30 @@ Some examples:

```bash
$ cz bump --help
usage: cz bump [-h] [--dry-run] [--files-only] [--changelog] [--no-verify]
[--yes] [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
[--prerelease {alpha,beta,rc}]
[--increment {MAJOR,MINOR,PATCH}] [--check-consistency]
usage: cz bump [-h] [--dry-run] [--files-only] [--changelog] [--no-verify] [--yes]
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
[--increment {MAJOR,MINOR,PATCH}] [--check-consistency] [--annotated-tag]

optional arguments:
-h, --help show this help message and exit
--dry-run show output to stdout, no commit, no modified files
--files-only bump version in the files from the config
--changelog, -ch generate the changelog for the newest version
--no-verify this option bypasses the pre-commit and commit-msg
hooks
--no-verify this option bypasses the pre-commit and commit-msg hooks
--yes accept automatically questions done
--tag-format TAG_FORMAT
the format used to tag the commit and read it, use it
in existing projects, wrap around simple quotes
the format used to tag the commit and read it, use it in existing projects, wrap
around simple quotes
--bump-message BUMP_MESSAGE
template used to create the release commit, useful
when working with CI
template used to create the release commit, useful when working with CI
--prerelease {alpha,beta,rc}, -pr {alpha,beta,rc}
choose type of prerelease
--increment {MAJOR,MINOR,PATCH}
manually specify the desired increment
--check-consistency, -cc
check consistency among versions defined in commitizen
configuration and version_files
check consistency among versions defined in commitizen configuration and
version_files
--annotated-tag, -at create annotated tag instead of lightweight one
```

### `--changelog`
Expand Down Expand Up @@ -216,6 +214,15 @@ Some examples
bump_message = "release $current_version → $new_version [skip-ci]"
```

### `annotated_tag`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency, I'll suggest using --annotated_tag


Whether to create annotated tags or lightweight ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my understand is correct, we can use cz bump -at and set it in config to achive it. If so, I'd suggest adding both usages here.

```toml
[tool.commitizen]
annotated_tag = true
```

## Custom bump

Read the [customizing section](./customization.md).
Expand Down
32 changes: 31 additions & 1 deletion tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,37 @@ def test_bump_minor_increment(commit_msg, mocker):
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True
cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"')
assert tag_exists is True and "commit:refs/tags/0.2.0\n" in cmd_res.out


@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_minor_increment_annotated(commit_msg, mocker):
create_file_and_commit(commit_msg)
testargs = ["cz", "bump", "--yes", "--annotated-tag"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"')
assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out


@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
def test_bump_minor_increment_annotated_config_file(
commit_msg, mocker, tmp_commitizen_project
):
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_commitizen_cfg_file.write(
f"{tmp_commitizen_cfg_file.read()}\n" f"annotated_tag = 1"
)
create_file_and_commit(commit_msg)
testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"')
assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out


@pytest.mark.usefixtures("tmp_commitizen_project")
Expand Down