Skip to content

Commit c64d770

Browse files
committed
fix: Ignore path conflicts and use spawn instead of exec
1 parent 19dc12b commit c64d770

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/cli.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,28 @@ import * as log from './logger';
1111
import { Configuration, InputType, DiffyType } from './types';
1212
import * as utils from './utils';
1313

14+
const defaultArgs = ['-M', '-C', 'HEAD'];
15+
1416
function runGitDiff(gitArgsArr: string[], ignore: string[]): string {
15-
const baseArgs = gitArgsArr.length > 0 ? gitArgsArr.map(arg => `"${arg}"`) : ['-M', '-C', 'HEAD'];
16-
const colorArgs = gitArgsArr.indexOf('--no-color') < 0 ? ['--no-color'] : [];
17-
const ignoreArgs = ignore.map(file => `":(exclude)${file}"`);
17+
const gitDiffArgs: string[] = ['diff'];
18+
19+
if (!gitArgsArr.includes('--no-color')) gitDiffArgs.push('--no-color');
1820

19-
const diffCommand = `git diff ${baseArgs.join(' ')} ${colorArgs.join(' ')} ${ignoreArgs.join(' ')}`;
21+
if (gitArgsArr.length === 0) Array.prototype.push.apply(gitDiffArgs, defaultArgs);
22+
23+
Array.prototype.push.apply(
24+
gitDiffArgs,
25+
gitArgsArr.map(arg => `"${arg}"`),
26+
);
27+
28+
if (!gitArgsArr.includes('--')) gitDiffArgs.push('--');
29+
30+
Array.prototype.push.apply(
31+
gitDiffArgs,
32+
ignore.map(file => `":(exclude)${file}"`),
33+
);
2034

21-
return utils.execute(diffCommand);
35+
return utils.execute('git', gitDiffArgs);
2236
}
2337

2438
function prepareHTML(diffHTMLContent: string, config: Configuration): string {

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export function writeFile(filePath: string, content: string): void {
2828
return fs.writeFileSync(filePath, content);
2929
}
3030

31-
export function execute(cmd: string): string {
32-
return childProcess.execSync(cmd).toString('utf8');
31+
export function execute(executable: string, args: string[]): string {
32+
return childProcess.spawnSync(executable, args, { encoding: 'utf8' }).stdout;
3333
}
3434

3535
export function replaceExactly(value: string, searchValue: string, replaceValue: string): string {

0 commit comments

Comments
 (0)