-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pathspec / file lists supported in all TaskOptions (#924)
Add the ability to append pathspec / file paths to the parameters passed through to git, automatically adding the `--` argument to separate file paths from the rest of the git command. Closes #914
- Loading branch information
Showing
13 changed files
with
194 additions
and
6 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
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,5 @@ | ||
--- | ||
'simple-git': minor | ||
--- | ||
|
||
Create a utility to append pathspec / file lists to tasks through the TaskOptions array/object |
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,16 @@ | ||
const cache = new WeakMap<String, string[]>(); | ||
|
||
export function pathspec(...paths: string[]) { | ||
const key = new String(paths); | ||
cache.set(key, paths); | ||
|
||
return key as string; | ||
} | ||
|
||
export function isPathSpec(path: string | unknown): path is string { | ||
return path instanceof String && cache.has(path); | ||
} | ||
|
||
export function toPaths(pathSpec: string): string[] { | ||
return cache.get(pathSpec) || []; | ||
} |
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,34 @@ | ||
import { SimpleGitPlugin } from './simple-git-plugin'; | ||
import { isPathSpec, toPaths } from '../args/pathspec'; | ||
|
||
export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> { | ||
return { | ||
type: 'spawn.args', | ||
action(data) { | ||
const prefix: string[] = []; | ||
const suffix: string[] = []; | ||
|
||
for (let i = 0; i < data.length; i++) { | ||
const param = data[i]; | ||
|
||
if (isPathSpec(param)) { | ||
suffix.push(...toPaths(param)); | ||
continue; | ||
} | ||
|
||
if (param === '--') { | ||
suffix.push( | ||
...data | ||
.slice(i + 1) | ||
.flatMap((item) => (isPathSpec(item) && toPaths(item)) || item) | ||
); | ||
break; | ||
} | ||
|
||
prefix.push(param); | ||
} | ||
|
||
return !suffix.length ? prefix : [...prefix, '--', ...suffix.map(String)]; | ||
}, | ||
}; | ||
} |
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
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,56 @@ | ||
import { SimpleGit } from '../../typings'; | ||
import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; | ||
import { pathspec } from '../../src/lib/args/pathspec'; | ||
|
||
describe('suffixPathsPlugin', function () { | ||
let git: SimpleGit; | ||
|
||
beforeEach(() => (git = newSimpleGit())); | ||
|
||
it('moves pathspec to end', async () => { | ||
git.raw(['a', pathspec('b'), 'c']); | ||
await closeWithSuccess(); | ||
|
||
assertExecutedCommands('a', 'c', '--', 'b'); | ||
}); | ||
|
||
it('moves multiple pathspecs to end', async () => { | ||
git.raw(['a', pathspec('b'), 'c', pathspec('d'), 'e']); | ||
await closeWithSuccess(); | ||
|
||
assertExecutedCommands('a', 'c', 'e', '--', 'b', 'd'); | ||
}); | ||
|
||
it('ignores processing after a pathspec split', async () => { | ||
git.raw('a', pathspec('b'), '--', 'c', pathspec('d'), 'e'); | ||
await closeWithSuccess(); | ||
|
||
assertExecutedCommands('a', '--', 'b', 'c', 'd', 'e'); | ||
}); | ||
|
||
it('flattens pathspecs after an explicit splitter', async () => { | ||
git.raw('a', '--', 'b', pathspec('c', 'd'), 'e'); | ||
await closeWithSuccess(); | ||
|
||
assertExecutedCommands('a', '--', 'b', 'c', 'd', 'e'); | ||
}); | ||
|
||
it('accepts multiple paths in one pathspec argument', async () => { | ||
git.raw('a', pathspec('b', 'c'), 'd'); | ||
await closeWithSuccess(); | ||
|
||
assertExecutedCommands('a', 'd', '--', 'b', 'c'); | ||
}); | ||
|
||
it('accepted as value of an option', async () => { | ||
git.pull({ | ||
foo: null, | ||
blah1: pathspec('a', 'b'), | ||
blah2: pathspec('c', 'd'), | ||
bar: null, | ||
}); | ||
|
||
await closeWithSuccess(); | ||
assertExecutedCommands('pull', 'foo', 'bar', '--', 'a', 'b', 'c', 'd'); | ||
}); | ||
}); |
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