From 2ab193675b2a90a1c35cb2921aa96c0d9c26424d Mon Sep 17 00:00:00 2001 From: Thomas Zub Date: Wed, 21 Jun 2023 11:51:08 +0200 Subject: [PATCH] fix: keep splitter if no path specs exist (#929) --- .changeset/nice-laws-invite.md | 5 +++++ simple-git/src/lib/plugins/suffix-paths.plugin.ts | 5 ++++- simple-git/test/unit/plugin.pathspec.spec.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/nice-laws-invite.md diff --git a/.changeset/nice-laws-invite.md b/.changeset/nice-laws-invite.md new file mode 100644 index 00000000..791c9879 --- /dev/null +++ b/.changeset/nice-laws-invite.md @@ -0,0 +1,5 @@ +--- +'simple-git': patch +--- + +keep path splitter without path specs diff --git a/simple-git/src/lib/plugins/suffix-paths.plugin.ts b/simple-git/src/lib/plugins/suffix-paths.plugin.ts index 1181f487..4af32f19 100644 --- a/simple-git/src/lib/plugins/suffix-paths.plugin.ts +++ b/simple-git/src/lib/plugins/suffix-paths.plugin.ts @@ -7,16 +7,19 @@ export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> { action(data) { const prefix: string[] = []; const suffix: string[] = []; + let suffixFound: boolean = false; for (let i = 0; i < data.length; i++) { const param = data[i]; if (isPathSpec(param)) { + suffixFound = true; suffix.push(...toPaths(param)); continue; } if (param === '--') { + suffixFound = true; suffix.push( ...data .slice(i + 1) @@ -28,7 +31,7 @@ export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> { prefix.push(param); } - return !suffix.length ? prefix : [...prefix, '--', ...suffix.map(String)]; + return suffixFound ? [...prefix, '--', ...suffix.map(String)] : prefix; }, }; } diff --git a/simple-git/test/unit/plugin.pathspec.spec.ts b/simple-git/test/unit/plugin.pathspec.spec.ts index b7b70bb8..6b75b31f 100644 --- a/simple-git/test/unit/plugin.pathspec.spec.ts +++ b/simple-git/test/unit/plugin.pathspec.spec.ts @@ -53,4 +53,12 @@ describe('suffixPathsPlugin', function () { await closeWithSuccess(); assertExecutedCommands('pull', 'foo', 'bar', '--', 'a', 'b', 'c', 'd'); }); + + it('keep splitter without path specs', async () => { + git.raw(['a', '--']); + await closeWithSuccess(); + + assertExecutedCommands('a', '--'); + }); + });