Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1c1e57

Browse files
crai0Lee-W
authored andcommitted
refactor(utils): move backup path creation to utils
1 parent 2532003 commit f1c1e57

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

‎commitizen/commands/commit.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from commitizen import factory, git, out
88
from commitizen.config import BaseConfig
99
from commitizen.cz.exceptions import CzException
10+
from commitizen.cz.utils import get_backup_file_path
1011
from commitizen.exceptions import (
1112
CommitError,
1213
CustomError,
@@ -31,13 +32,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
3132
self.encoding = config.settings["encoding"]
3233
self.cz = factory.commiter_factory(self.config)
3334
self.arguments = arguments
34-
self.temp_file: str = os.path.join(
35-
tempfile.gettempdir(),
36-
"cz.commit%{user}%{project_root}.backup".format(
37-
user=os.environ.get("USER", ""),
38-
project_root=str(git.find_git_project_root()).replace("/", "%"),
39-
),
40-
)
35+
self.temp_file: str = get_backup_file_path()
4136

4237
def read_backup_message(self) -> str | None:
4338
# Check the commit backup file exists

‎commitizen/cz/utils.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import re
2+
import os
3+
import tempfile
24

35
from commitizen.cz import exceptions
6+
from commitizen import git
47

58

69
def required_validator(answer, msg=None):
@@ -15,3 +18,13 @@ def multiple_line_breaker(answer, sep="|"):
1518

1619
def strip_local_version(version: str) -> str:
1720
return re.sub(r"\+.+", "", version)
21+
22+
23+
def get_backup_file_path() -> str:
24+
return os.path.join(
25+
tempfile.gettempdir(),
26+
"cz.commit%{user}%{project_root}.backup".format(
27+
user=os.environ.get("USER", ""),
28+
project_root=str(git.find_git_project_root()).replace("/", "%"),
29+
),
30+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /