Skip to content

Commit

Permalink
feat: optionally include ignored files in StatusResult
Browse files Browse the repository at this point in the history
- When `git.status` is called with the `--ignored` flag, the `StatusResult` response will include an extra `ignored: string[]` property of ignored paths.

Closes #718
  • Loading branch information
steveukx committed Jan 23, 2022
1 parent 9089fc8 commit 70e6767
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion simple-git/src/lib/responses/StatusSummary.ts
Expand Up @@ -9,6 +9,7 @@ export class StatusSummary implements StatusResult {
public conflicted = [];
public created = [];
public deleted = [];
public ignored = undefined;
public modified = [];
public renamed = [];
public files = [];
Expand Down Expand Up @@ -81,6 +82,9 @@ const parsers: Map<string, StatusLineParser> = new Map([
append(result.renamed, renamed);
append(result.modified, renamed.to);
}),
parser(PorcelainFileStatus.IGNORED, PorcelainFileStatus.IGNORED, (_result, _file) => {
append((_result.ignored = _result.ignored || []), _file);
}),

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

Expand Down Expand Up @@ -145,7 +149,7 @@ function splitLine(result: StatusResult, lineStr: string) {
handler(result, path);
}

if (raw !== '##') {
if (raw !== '##' && raw !== '!!') {
result.files.push(new FileStatusSummary(path, index, workingDir));
}
}
Expand Down
4 changes: 4 additions & 0 deletions simple-git/test/unit/__fixtures__/responses/status.ts
Expand Up @@ -20,6 +20,10 @@ export function stagedModified(file = 'staged-modified.ext') {
return `M ${file}`;
}

export function stagedIgnored(file = 'ignored.ext') {
return `!! ${file}`;
}

export function statusResponse(branch = 'main', ...files: Array<string | (() => string)>) {
const stdOut: string[] = [
`## ${branch}`,
Expand Down
11 changes: 10 additions & 1 deletion simple-git/test/unit/status.spec.ts
Expand Up @@ -8,6 +8,7 @@ import {
newSimpleGit,
newSimpleGitP,
stagedDeleted,
stagedIgnored,
stagedModified,
stagedRenamed,
stagedRenamedWithModifications,
Expand Down Expand Up @@ -142,7 +143,15 @@ describe('status', () => {
}
],
}))
})
});

it('Handles ignored files', () => {
expect(parseStatusSummary(statusResponse('main', stagedIgnored).stdOut)).toEqual(like({
...empty,
ignored: ['ignored.ext'],
files: [],
}));
});

it('Handles malformatted rename', () => {
expect(parseStatusSummary(statusResponse('main', 'R file.ext').stdOut)).toEqual(like({
Expand Down
9 changes: 9 additions & 0 deletions simple-git/typings/response.d.ts
Expand Up @@ -308,6 +308,15 @@ export interface StatusResult {
conflicted: string[];
created: string[];
deleted: string[];

/**
* Ignored files are not listed by default, add `--ignored` to the task options in order to see
* this array of ignored files/paths.
*
* Note: ignored files will not be added to the `files` array, and will not be included in the
* `isClean()` calculation.
*/
ignored?: string[];
modified: string[];
renamed: StatusResultRenamed[];
staged: string[];
Expand Down

0 comments on commit 70e6767

Please sign in to comment.