Skip to content

Allow passing repeated options to git #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-zoos-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'simple-git': minor
---

Allow repeating git options like `{'--opt': ['value1', 'value2']}`
2 changes: 1 addition & 1 deletion simple-git/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TaskOptions<O extends Options = Options> = string[] | O;
/**
* Options supplied in most tasks as an optional trailing object
*/
export type OptionsValues = null | string | number;
export type OptionsValues = null | string | number | (string | number)[];
export type Options = Record<string, OptionsValues>;

export type OptionFlags<FLAGS extends string, VALUE = null> = Partial<Record<FLAGS, VALUE>>;
Expand Down
2 changes: 2 additions & 0 deletions simple-git/src/lib/utils/task-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function appendTaskOptions<T extends Options = Options>(
commands.push(value);
} else if (filterPrimitives(value, ['boolean'])) {
commands.push(key + '=' + value);
} else if (Array.isArray(value)) {
commands.push(...value.map((v) => key + '=' + v));
} else {
commands.push(key);
}
Expand Down
7 changes: 7 additions & 0 deletions simple-git/test/unit/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ describe('push', () => {
assertExecutedCommands('push', '--follow-tags', ...defaultCommands);
});

it('git push with multiple --push-options', async () => {
git.push({ '--push-option': ["foo", "foo=bar", 123] });
await closeWithSuccess();

assertExecutedCommands('push', '--push-option=foo', '--push-option=foo=bar', '--push-option=123', ...defaultCommands);
});

it('git push with remote/branch and options', async () => {
git.push('rrr', 'bbb', { '--follow-tags': null });
await closeWithSuccess();
Expand Down