Skip to content

Commit 7e5e6da

Browse files
author
Ognjen Jevremovic
committed
fix(git-cz.js,staging.js): check for staged files before running prompt
Check for staged files before running the prompt. Running the `git-cz` command with no files staged reports "No files added to staging". Preserve the functionality of `git -a` (--all) flag - `git-cz -a` command with no files added to staging area, adds all files to staging and opens the prompt (no error thrown). "fix commitizen#785"
1 parent 12442c1 commit 7e5e6da

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/cli/strategies/git-cz.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
4141
let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
4242
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath);
4343
let prompter = getPrompter(adapterConfig.path);
44+
let shouldStageAllFiles = rawGitArgs.includes('-a') || rawGitArgs.includes('--all');
4445

4546
isClean(process.cwd(), function (error, stagingIsClean) {
4647
if (error) {
@@ -67,6 +68,6 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
6768
throw error;
6869
}
6970
});
70-
});
71+
}, shouldStageAllFiles);
7172

7273
}

src/commitizen/staging.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export { isClean };
55
/**
66
* Asynchrounously determines if the staging area is clean
77
*/
8-
function isClean (repoPath, done) {
9-
exec('git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only', {
8+
function isClean (repoPath, done, stageAllFiles) {
9+
exec(`git diff --cached --no-ext-diff --name-only ${!!stageAllFiles ? '&& git diff --no-ext-diff --name-only' : ''}`, {
1010
maxBuffer: Infinity,
1111
cwd: repoPath
1212
}, function (error, stdout) {

0 commit comments

Comments
 (0)