Skip to content

Commit

Permalink
Merge pull request #932 from steveukx/pr/930
Browse files Browse the repository at this point in the history
Pr/930
  • Loading branch information
steveukx authored Jun 26, 2023
2 parents f101061 + fea8551 commit 411ac6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-laws-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'simple-git': patch
---

keep path splitter without path specs
15 changes: 8 additions & 7 deletions simple-git/src/lib/plugins/suffix-paths.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> {
type: 'spawn.args',
action(data) {
const prefix: string[] = [];
const suffix: string[] = [];
let suffix: undefined | string[];
function append(args: string[]) {
(suffix = suffix || []).push(...args);
}

for (let i = 0; i < data.length; i++) {
const param = data[i];

if (isPathSpec(param)) {
suffix.push(...toPaths(param));
append(toPaths(param));
continue;
}

if (param === '--') {
suffix.push(
...data
.slice(i + 1)
.flatMap((item) => (isPathSpec(item) && toPaths(item)) || item)
append(
data.slice(i + 1).flatMap((item) => (isPathSpec(item) && toPaths(item)) || item)
);
break;
}

prefix.push(param);
}

return !suffix.length ? prefix : [...prefix, '--', ...suffix.map(String)];
return !suffix ? prefix : [...prefix, '--', ...suffix.map(String)];
},
};
}
7 changes: 7 additions & 0 deletions simple-git/test/unit/plugin.pathspec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ 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', '--');
});
});

0 comments on commit 411ac6b

Please sign in to comment.