Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c4dae52

Browse files
DranaxelAdrianDC
authored andcommitted
feat(commit): add '--allow-empty' flag to commit command
Signed-off-by: Adrian DC <radian.dc@gmail.com>
1 parent 63a9a1e commit c4dae52

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

commitizen/cli.py

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def __call__(
162162
"default": 0,
163163
"help": "length limit of the commit message; 0 for no limit",
164164
},
165+
{
166+
"name": "--allow-empty",
167+
"action": "store_true",
168+
"help": "Allow to create a commit without staging changes",
169+
},
165170
],
166171
},
167172
{

commitizen/commands/commit.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ def prompt_commit_questions(self) -> str:
7373
return message
7474

7575
def __call__(self):
76+
allow_empty: bool = self.arguments.get("allow_empty")
7677
dry_run: bool = self.arguments.get("dry_run")
7778
write_message_to_file: bool = self.arguments.get("write_message_to_file")
7879

7980
is_all: bool = self.arguments.get("all")
8081
if is_all:
8182
c = git.add("-u")
8283

83-
if git.is_staging_clean() and not dry_run:
84+
if git.is_staging_clean() and not (dry_run or allow_empty):
8485
raise NothingToCommitError("No files added to staging!")
8586

8687
if write_message_to_file is not None and write_message_to_file.is_dir():
@@ -125,6 +126,11 @@ def __call__(self):
125126
extra_args += " "
126127
extra_args += "-s"
127128

129+
if allow_empty:
130+
if extra_args:
131+
extra_args += " "
132+
extra_args += "--allow-empty"
133+
128134
c = git.commit(m, args=extra_args)
129135

130136
if c.return_code != 0:

0 commit comments

Comments
 (0)