Skip to content

Commit 70e6767

Browse files
committed
feat: optionally include ignored files in StatusResult
- When `git.status` is called with the `--ignored` flag, the `StatusResult` response will include an extra `ignored: string[]` property of ignored paths. Closes #718
1 parent 9089fc8 commit 70e6767

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

simple-git/src/lib/responses/StatusSummary.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class StatusSummary implements StatusResult {
99
public conflicted = [];
1010
public created = [];
1111
public deleted = [];
12+
public ignored = undefined;
1213
public modified = [];
1314
public renamed = [];
1415
public files = [];
@@ -81,6 +82,9 @@ const parsers: Map<string, StatusLineParser> = new Map([
8182
append(result.renamed, renamed);
8283
append(result.modified, renamed.to);
8384
}),
85+
parser(PorcelainFileStatus.IGNORED, PorcelainFileStatus.IGNORED, (_result, _file) => {
86+
append((_result.ignored = _result.ignored || []), _file);
87+
}),
8488

8589
parser(PorcelainFileStatus.UNTRACKED, PorcelainFileStatus.UNTRACKED, (result, file) => append(result.not_added, file)),
8690

@@ -145,7 +149,7 @@ function splitLine(result: StatusResult, lineStr: string) {
145149
handler(result, path);
146150
}
147151

148-
if (raw !== '##') {
152+
if (raw !== '##' && raw !== '!!') {
149153
result.files.push(new FileStatusSummary(path, index, workingDir));
150154
}
151155
}

simple-git/test/unit/__fixtures__/responses/status.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function stagedModified(file = 'staged-modified.ext') {
2020
return `M ${file}`;
2121
}
2222

23+
export function stagedIgnored(file = 'ignored.ext') {
24+
return `!! ${file}`;
25+
}
26+
2327
export function statusResponse(branch = 'main', ...files: Array<string | (() => string)>) {
2428
const stdOut: string[] = [
2529
`## ${branch}`,

simple-git/test/unit/status.spec.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
newSimpleGit,
99
newSimpleGitP,
1010
stagedDeleted,
11+
stagedIgnored,
1112
stagedModified,
1213
stagedRenamed,
1314
stagedRenamedWithModifications,
@@ -142,7 +143,15 @@ describe('status', () => {
142143
}
143144
],
144145
}))
145-
})
146+
});
147+
148+
it('Handles ignored files', () => {
149+
expect(parseStatusSummary(statusResponse('main', stagedIgnored).stdOut)).toEqual(like({
150+
...empty,
151+
ignored: ['ignored.ext'],
152+
files: [],
153+
}));
154+
});
146155

147156
it('Handles malformatted rename', () => {
148157
expect(parseStatusSummary(statusResponse('main', 'R file.ext').stdOut)).toEqual(like({

simple-git/typings/response.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ export interface StatusResult {
308308
conflicted: string[];
309309
created: string[];
310310
deleted: string[];
311+
312+
/**
313+
* Ignored files are not listed by default, add `--ignored` to the task options in order to see
314+
* this array of ignored files/paths.
315+
*
316+
* Note: ignored files will not be added to the `files` array, and will not be included in the
317+
* `isClean()` calculation.
318+
*/
319+
ignored?: string[];
311320
modified: string[];
312321
renamed: StatusResultRenamed[];
313322
staged: string[];

0 commit comments

Comments
 (0)