-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `config: string[]` property to the `SimpleGitOptions` object used to configure the `simple-git` instance. When supplied, the strings are prefixed to all commands run by that instance as configuration options (ie: they are prefixed themselves with the `-c` flag). Closes #562 - allows supplying custom proxies to the full set of API commands Closes #559 - allows global commands
- Loading branch information
Showing
14 changed files
with
152 additions
and
22 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
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,13 @@ | ||
import { prefixedArray } from '../utils'; | ||
import { SimpleGitPlugin } from './simple-git-plugin'; | ||
|
||
export function commandConfigPrefixingPlugin(configuration: string[]): SimpleGitPlugin<'spawn.args'> { | ||
const prefix = prefixedArray(configuration, '-c'); | ||
|
||
return { | ||
type: 'spawn.args', | ||
action(data) { | ||
return [...prefix, ...data]; | ||
}, | ||
}; | ||
} |
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,3 @@ | ||
export * from './command-config-prefixing-plugin'; | ||
export * from './plugin-store'; | ||
export * from './simple-git-plugin'; |
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,27 @@ | ||
import { SimpleGitPlugin, SimpleGitPluginType, SimpleGitPluginTypes } from './simple-git-plugin'; | ||
|
||
export class PluginStore { | ||
|
||
private plugins: Set<SimpleGitPlugin<SimpleGitPluginType>> = new Set(); | ||
|
||
public add<T extends SimpleGitPluginType>(plugin: SimpleGitPlugin<T>) { | ||
this.plugins.add(plugin); | ||
return () => { | ||
this.plugins.delete(plugin); | ||
}; | ||
} | ||
|
||
public exec<T extends SimpleGitPluginType>(type: T, data: SimpleGitPluginTypes[T]['data'], context: SimpleGitPluginTypes[T]['context']): typeof data { | ||
let output = data; | ||
const contextual = Object.freeze(Object.create(context)); | ||
|
||
for (const plugin of this.plugins) { | ||
if (plugin.type === type) { | ||
output = plugin.action(output, contextual); | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
} |
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,14 @@ | ||
export interface SimpleGitPluginTypes { | ||
'spawn.args': { | ||
data: string[]; | ||
context: {}; | ||
}; | ||
} | ||
|
||
export type SimpleGitPluginType = keyof SimpleGitPluginTypes; | ||
|
||
export interface SimpleGitPlugin<T extends SimpleGitPluginType> { | ||
action(data: SimpleGitPluginTypes[T]['data'], context: SimpleGitPluginTypes[T]['context']): typeof data; | ||
|
||
type: T; | ||
} |
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
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 @@ | ||
import { SimpleGit } from '../../typings'; | ||
import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; | ||
|
||
describe('plugins', () => { | ||
|
||
let git: SimpleGit; | ||
|
||
it('allows configuration prefixing', async () => { | ||
git = newSimpleGit({ config: ['a', 'bcd'] }); | ||
git.raw('foo'); | ||
|
||
await closeWithSuccess(); | ||
assertExecutedCommands('-c', 'a', '-c', 'bcd', 'foo'); | ||
}) | ||
|
||
}) |