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 ff56b4e

Browse files
committed
feat(commit): add --write-message-to-file option
1 parent bcd3988 commit ff56b4e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

‎commitizen/cli.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@
6262
"action": "store_true",
6363
"help": "show output to stdout, no commit, no modified files",
6464
},
65+
{
66+
"name": "--write-message-to-file",
67+
"metavar": "FILE_PATH",
68+
"help": "write message to file before commiting (can be combined with --dry-run)",
69+
},
6570
{
6671
"name": ["-s", "--signoff"],
6772
"action": "store_true",
68-
"help": "Sign off the commit",
73+
"help": "sign off the commit",
6974
},
7075
],
7176
},

‎commitizen/commands/commit.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
NoAnswersError,
1515
NoCommitBackupError,
1616
NotAGitProjectError,
17+
NotAllowed,
1718
NothingToCommitError,
1819
)
1920
from commitizen.git import smart_open
@@ -63,10 +64,18 @@ def prompt_commit_questions(self) -> str:
6364

6465
def __call__(self):
6566
dry_run: bool = self.arguments.get("dry_run")
67+
write_message_to_file = self.arguments.get("write_message_to_file")
6668

6769
if git.is_staging_clean() and not dry_run:
6870
raise NothingToCommitError("No files added to staging!")
6971

72+
if write_message_to_file is not None:
73+
if not isinstance(write_message_to_file, str):
74+
raise NotAllowed(
75+
"Commit message file name is broken.\n"
76+
"Check the flag `--write-message-to-file` in the terminal"
77+
)
78+
7079
retry: bool = self.arguments.get("retry")
7180

7281
if retry:
@@ -76,6 +85,10 @@ def __call__(self):
7685

7786
out.info(f"\n{m}\n")
7887

88+
if write_message_to_file:
89+
with smart_open(write_message_to_file, "w") as file:
90+
file.write(m)
91+
7992
if dry_run:
8093
raise DryRunExit()
8194

0 commit comments

Comments
(0)

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