-
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use new
--diff
and --diff-filter
options when checking task …
…modifications
- Loading branch information
1 parent
32806da
commit 1a5a66a
Showing
5 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function getDiffCommand(diff, diffFilter) { | ||
/** | ||
* Docs for --diff-filter option: | ||
* @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 | ||
*/ | ||
const diffFilterArg = diffFilter !== undefined ? diffFilter.trim() : 'ACMR' | ||
|
||
/** Use `--diff branch1...branch2` or `--diff="branch1 branch2", or fall back to default staged files */ | ||
const diffArgs = diff !== undefined ? diff.trim().split(' ') : ['--staged'] | ||
|
||
/** | ||
* Docs for -z option: | ||
* @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z | ||
*/ | ||
const diffCommand = ['diff', '--name-only', '-z', `--diff-filter=${diffFilterArg}`, ...diffArgs] | ||
|
||
return diffCommand | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getDiffCommand } from '../../lib/getDiffCommand.js' | ||
|
||
describe('chunkFiles', () => { | ||
const customDiffString = 'origin/main..custom-branch' | ||
const customDiffSpaceSeparatedString = 'origin/main custom-branch' | ||
const customDiffFilter = 'a' | ||
|
||
it('should default to sane value', () => { | ||
const diff = getDiffCommand() | ||
expect(diff).toEqual(['diff', '--name-only', '-z', `--diff-filter=ACMR`, '--staged']) | ||
}) | ||
|
||
it('should work only with diff set as string', () => { | ||
const diff = getDiffCommand(customDiffString) | ||
expect(diff).toEqual([ | ||
'diff', | ||
'--name-only', | ||
'-z', | ||
`--diff-filter=ACMR`, | ||
'origin/main..custom-branch', | ||
]) | ||
}) | ||
|
||
it('should work only with diff set as space separated string', () => { | ||
const diff = getDiffCommand(customDiffSpaceSeparatedString) | ||
expect(diff).toEqual([ | ||
'diff', | ||
'--name-only', | ||
'-z', | ||
`--diff-filter=ACMR`, | ||
'origin/main', | ||
'custom-branch', | ||
]) | ||
}) | ||
|
||
it('should work only with diffFilter set', () => { | ||
const diff = getDiffCommand(undefined, customDiffFilter) | ||
expect(diff).toEqual(['diff', '--name-only', '-z', `--diff-filter=a`, '--staged']) | ||
}) | ||
|
||
it('should work with both diff and diffFilter set', () => { | ||
const diff = getDiffCommand(customDiffString, customDiffFilter) | ||
expect(diff).toEqual([ | ||
'diff', | ||
'--name-only', | ||
'-z', | ||
`--diff-filter=a`, | ||
'origin/main..custom-branch', | ||
]) | ||
}) | ||
}) |