Skip to content
Merged
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
25 changes: 15 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Commitizen
=============

Python 3 command line utility to standardize commit messages and bump version
Python 3 command-line utility to standardize commit messages and bump version


.. image:: https://github.com/Woile/commitizen/workflows/Python%20package/badge.svg
Expand Down Expand Up @@ -43,13 +43,13 @@ About

Commitizen is a tool designed for teams.

Its main purpose is to define a standard way of commiting rules
Its main purpose is to define a standard way of committing rules
and communicating it (using the cli provided by commitizen).

The reasoning behind it is that is easier to read, and enforces writing
The reasoning behind it is that it is easier to read, and enforces writing
descriptive commits.

Besides that, having a convention on your commits, makes it possible to
Besides that, having a convention on your commits makes it possible to
parse them and use them for something else, like generating automatically
the version or a changelog.

Expand All @@ -75,7 +75,7 @@ Installation
Features
========

- Command line utility to create commits with your rules. Defaults: `conventional commits`_
- Command-line utility to create commits with your rules. Defaults: `conventional commits`_
- Display information about your commit rules (commands: schema, example, info)
- Bump version automatically using semantic verisoning based on the commits. `Read More <./docs/bump.md>`_
- Generate a changelog using "Keep a changelog" (Planned feature)
Expand All @@ -102,7 +102,7 @@ This is an example of how the git messages history would look like:
docs(README): added about, installation, creating, etc
feat(config): new loads from ~/.cz and working project .cz .cz.cfg and setup.cfg

And then using ``cz bump`` you can change the version of your project
And then, by using ``cz bump`` , you can change the version of your project.

``feat`` to ``MINOR``
``fix`` to ``PATCH``
Expand All @@ -111,7 +111,7 @@ And then using ``cz bump`` you can change the version of your project
Commitizens
===========

These are the available commiting styles by default:
These are the available committing styles by default:

* cz_conventional_commits: `conventional commits`_
* cz_jira: `jira smart commits <https://confluence.atlassian.com/fisheye/using-smart-commits-298976812.html>`_
Expand Down Expand Up @@ -156,18 +156,23 @@ Usage
optional arguments:
-h, --help show this help message and exit
--debug use debug mode
-n NAME, --name NAME use the given commitizen
-n NAME, --name NAME use the given commitizen (default:
cz_conventional_commits)
--version get the version of the installed commitizen

commands:
{ls,commit,c,example,info,schema,bump,check}
{ls,commit,c,example,info,schema,bump,version,check,init}
ls show available commitizens
commit (c) create new commit
example show commit example
info show information about the cz
schema show commit schema
bump bump semantic version based on the git log
check enforce the project to always use conventional commits
version get the version of the installed commitizen or the
current project (default: installed commitizen)
check validates that a commit message matches the commitizen
schema
init init commitizen configuration

Contributing
============
Expand Down
2 changes: 1 addition & 1 deletion commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{
"name": "--tag-format",
"help": (
"format used to tag the commmit and read it, "
"the format used to tag the commit and read it, "
"use it in existing projects, "
"wrap around simple quotes"
),
Expand Down
13 changes: 7 additions & 6 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

from commitizen import bump, factory, git, out
from commitizen.config import BaseConfig

NO_COMMITS_FOUND = 3
NO_VERSION_SPECIFIED = 4
NO_PATTERN_MAP = 7
COMMIT_FAILED = 8
TAG_FAILED = 9
from commitizen.error_codes import (
NO_COMMITS_FOUND,
NO_VERSION_SPECIFIED,
NO_PATTERN_MAP,
COMMIT_FAILED,
TAG_FAILED,
)


class Bump:
Expand Down
5 changes: 1 addition & 4 deletions commitizen/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from commitizen import factory, out
from commitizen.config import BaseConfig


NO_COMMIT_MSG = 3
INVALID_COMMIT_MSG = 5
from commitizen.error_codes import INVALID_COMMIT_MSG


class Check:
Expand Down
14 changes: 7 additions & 7 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from commitizen import factory, git, out
from commitizen.cz.exceptions import CzException
from commitizen.config import BaseConfig


NO_ANSWERS = 5
COMMIT_ERROR = 6
NO_COMMIT_BACKUP = 7
NOTHING_TO_COMMIT = 8
CUSTOM_ERROR = 9
from commitizen.error_codes import (
NO_ANSWERS,
COMMIT_ERROR,
NO_COMMIT_BACKUP,
NOTHING_TO_COMMIT,
CUSTOM_ERROR,
)


class Commit:
Expand Down
29 changes: 20 additions & 9 deletions commitizen/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
import warnings
from pathlib import Path
from typing import Optional

from commitizen import defaults
from commitizen import defaults, git, out
from commitizen.error_codes import NOT_A_GIT_PROJECT
from .base_config import BaseConfig
from .toml_config import TomlConfig
from .ini_config import IniConfig


def load_global_conf() -> Optional[IniConfig]:
home = str(Path.home())
global_cfg = os.path.join(home, ".cz")
if not os.path.exists(global_cfg):
home = Path.home()
global_cfg = home / Path(".cz")
Copy link
Member

Choose a reason for hiding this comment

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

nice

if not global_cfg.exists():
return None

# global conf doesnt make sense with commitizen bump
Expand All @@ -35,16 +35,27 @@ def load_global_conf() -> Optional[IniConfig]:
def read_cfg() -> BaseConfig:
conf = BaseConfig()

git_project_root = git.find_git_project_root()
if not git_project_root:
out.error(
"fatal: not a git repository (or any of the parent directories): .git"
)
raise SystemExit(NOT_A_GIT_PROJECT)

allowed_cfg_files = defaults.config_files
for filename in allowed_cfg_files:
config_file_exists = os.path.exists(filename)
if not config_file_exists:
cfg_paths = (
path / Path(filename)
for path in [Path("."), git_project_root]
for filename in allowed_cfg_files
)
for filename in cfg_paths:
if not filename.exists():
continue

with open(filename, "r") as f:
data: str = f.read()

if "toml" in filename:
if "toml" in filename.suffix:
_conf = TomlConfig(data=data, path=filename)
else:
warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def set_key(self, key, value):
For now only strings are supported.
We use to update the version number.
"""
return self
raise NotImplementedError()

def update(self, data: dict):
self._settings.update(data)
Expand Down
23 changes: 23 additions & 0 deletions commitizen/error_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Commitizen factory
NO_COMMITIZEN_FOUND = 1

# Config
NOT_A_GIT_PROJECT = 2

# Bump
NO_COMMITS_FOUND = 3
NO_VERSION_SPECIFIED = 4
NO_PATTERN_MAP = 5
COMMIT_FAILED = 6
TAG_FAILED = 7

# Commit
NO_ANSWERS = 8
COMMIT_ERROR = 9
NO_COMMIT_BACKUP = 10
NOTHING_TO_COMMIT = 11
CUSTOM_ERROR = 12

# Check
NO_COMMIT_MSG = 13
INVALID_COMMIT_MSG = 14
3 changes: 1 addition & 2 deletions commitizen/factory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from commitizen import BaseCommitizen, out
from commitizen.cz import registry
from commitizen.config import BaseConfig

NO_COMMITIZEN_FOUND = 2
from commitizen.error_codes import NO_COMMITIZEN_FOUND


def commiter_factory(config: BaseConfig) -> BaseCommitizen:
Expand Down
8 changes: 8 additions & 0 deletions commitizen/git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Optional, List

Expand Down Expand Up @@ -55,3 +56,10 @@ def get_all_tags() -> Optional[List[str]]:
if c.err:
return []
return [tag.strip() for tag in c.out.split("\n") if tag.strip()]


def find_git_project_root() -> Optional[Path]:
c = cmd.run("git rev-parse --show-toplevel")
if not c.err:
return Path(c.out.strip())
return None
12 changes: 6 additions & 6 deletions docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The version is bumped **automatically** based on the commits.

The commits should follow the rules of the commiter in order to be parsed properly.
The commits should follow the rules of the committer to be parsed correctly.

It is possible to specify a **prerelease** (alpha, beta, release candidate) version.

Expand Down Expand Up @@ -65,7 +65,7 @@ optional arguments:
--files-only bump version in the files from the config
--yes accept automatically questions done
--tag-format TAG_FORMAT
format used to tag the commmit and read it, use it in
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 commmit, useful
Expand All @@ -80,9 +80,9 @@ optional arguments:

### `tag_format`

Used to read the format from the git tags, and also to generate the tags.
It is used to read the format from the git tags, and also to generate the tags.

Supports 2 types of formats, a simple and a more complex.
Commitizen supports 2 types of formats, a simple and a more complex.

```bash
cz bump --tag_format="v$version"
Expand Down Expand Up @@ -122,7 +122,7 @@ Suppported variables:

### `version_files` *

Used to identify the files which should be updated with the new version.
It is used to identify the files which should be updated with the new version.
It is also possible to provide a pattern for each file, separated by colons (`:`).

Commitizen will update it's configuration file automatically (`pyproject.toml`, `.cz`) when bumping,
Expand Down Expand Up @@ -160,7 +160,7 @@ in a line containing the `version` substring.

### `bump_message`

Template used to specify the commit message generated when bumping
Template used to specify the commit message generated when bumping.

defaults to: `bump: version $current_version → $new_version`

Expand Down
Loading