Skip to content

Commit

Permalink
fix(git-cz.js,staging.js): check for staged files before running prompt
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
Ognjen Jevremovic committed Mar 25, 2021
1 parent 12442c1 commit 7e5e6da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cli/strategies/git-cz.js
Expand Up @@ -41,6 +41,7 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath);
let prompter = getPrompter(adapterConfig.path);
let shouldStageAllFiles = rawGitArgs.includes('-a') || rawGitArgs.includes('--all');

isClean(process.cwd(), function (error, stagingIsClean) {
if (error) {
Expand All @@ -67,6 +68,6 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
throw error;
}
});
});
}, shouldStageAllFiles);

}
4 changes: 2 additions & 2 deletions src/commitizen/staging.js
Expand Up @@ -5,8 +5,8 @@ export { isClean };
/**
* Asynchrounously determines if the staging area is clean
*/
function isClean (repoPath, done) {
exec('git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only', {
function isClean (repoPath, done, stageAllFiles) {
exec(`git diff --cached --no-ext-diff --name-only ${!!stageAllFiles ? '&& git diff --no-ext-diff --name-only' : ''}`, {
maxBuffer: Infinity,
cwd: repoPath
}, function (error, stdout) {
Expand Down

0 comments on commit 7e5e6da

Please sign in to comment.