Skip to content

Commit 3dba422

Browse files
committed
refactor(git): extract _create_commit_cmd_string
1 parent 50fd65f commit 3dba422

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

commitizen/git.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,22 @@ def commit(
181181
f.write(message.encode("utf-8"))
182182
f.close()
183183

184-
command = f'git commit {args} -F "{f.name}"'
185-
186-
if committer_date and os.name == "nt": # pragma: no cover
187-
# Using `cmd /v /c "{command}"` sets environment variables only for that command
188-
command = f'cmd /v /c "set GIT_COMMITTER_DATE={committer_date}&& {command}"'
189-
elif committer_date:
190-
command = f"GIT_COMMITTER_DATE={committer_date} {command}"
191-
184+
command = _create_commit_cmd_string(args, committer_date, f.name)
192185
c = cmd.run(command)
193186
os.unlink(f.name)
194187
return c
195188

196189

190+
def _create_commit_cmd_string(args: str, committer_date: str | None, name: str) -> str:
191+
command = f'git commit {args} -F "{name}"'
192+
if not committer_date:
193+
return command
194+
if os.name != "nt":
195+
return f"GIT_COMMITTER_DATE={committer_date} {command}"
196+
# Using `cmd /v /c "{command}"` sets environment variables only for that command
197+
return f'cmd /v /c "set GIT_COMMITTER_DATE={committer_date}&& {command}"'
198+
199+
197200
def get_commits(
198201
start: str | None = None,
199202
end: str = "HEAD",

0 commit comments

Comments
 (0)