Skip to content

Commit 0037161

Browse files
authored
Merge branch 'steveukx:main' into patch-1
2 parents 18d6555 + d184c13 commit 0037161

38 files changed

+741
-120
lines changed

.changeset/config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"access": "public",
77
"baseBranch": "main",
88
"updateInternalDependencies": "patch",
9-
"ignore": []
9+
"ignore": [
10+
"@simple-git/test-utils"
11+
]
1012
}

docs/PLUGIN-ERRORS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
By default, `simple-git` will determine that a `git` task has resulted in an error when the process exit
44
code is anything other than `0` and there has been some data sent to the `stdErr` stream. Error handlers
5-
will be passed the content of both `stdOut` and `stdErr` concatenated together.
5+
will be passed the content of both `stdOut` and `stdErr` concatenated together.
66

77
To change any of this behaviour, configure the `simple-git` with the `errors` plugin with a function to be
88
called after every task has been run and should return either `undefined` when the task is treated as
@@ -21,7 +21,7 @@ const git = simpleGit({
2121
if (error) return error;
2222

2323
// customise the `errorCode` values to treat as success
24-
if (result.errorCode === 0) {
24+
if (result.exitCode === 0) {
2525
return;
2626
}
2727

docs/PLUGIN-TIMEOUT.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ To handle the case where the underlying `git` processes appear to hang, configur
88
import { simpleGit, GitPluginError, SimpleGit, SimpleGitProgressEvent } from 'simple-git';
99

1010
const git: SimpleGit = simpleGit({
11-
baseDir: '/some/path',
1211
timeout: {
1312
block: 2000,
1413
},
@@ -25,3 +24,55 @@ catch (err) {
2524
}
2625
}
2726
```
27+
28+
## Task Timeouts and Progress Events
29+
30+
The default behaviour of the timeout plugin is to listen for data being received on both the
31+
`stdOut` and `stdErr` streams from the `git` child process.
32+
33+
When using the `progress` plugin, `git` will be streaming regular progress updates to `stdErr`,
34+
so you may see that the timeout is never reached and `simple-git` patiently waits for `git` to
35+
finish whatever it is doing.
36+
37+
Configure this with the optional `stdOut` and `stdErr` properties of the `timeout` plugin
38+
configuration:
39+
40+
```typescript
41+
import { simpleGit, SimpleGit } from "simple-git";
42+
43+
const git: SimpleGit = simpleGit({
44+
progress({method, stage, progress}) {
45+
console.log(`git.${method} ${stage} stage ${progress}% complete`);
46+
},
47+
timeout: {
48+
block: 2000,
49+
stdOut: true, // default behaviour, resets the 2s timer every time data arrives on stdOut
50+
stdErr: false // custom behaviour, ignore the progress events being written to stdErr
51+
}
52+
});
53+
54+
```
55+
56+
## Absolute or Block Timeouts
57+
58+
The timeout plugin will reset its timers whenever data is received meaning the plugin will
59+
only kill processes that appear to be hanging and allow intentionally long-running processes
60+
to continue uninterrupted.
61+
62+
To change this default behaviour so that the plugin kills all processes after the supplied
63+
timeout, configure it so the plugin doesn't listen for data updates by supplying the optional
64+
`stdOut` and `stdErr` properties of the `timeout` plugin configuration:
65+
66+
```typescript
67+
import { simpleGit, SimpleGit } from "simple-git";
68+
69+
// create a simple-git instance that kills any process after 5s
70+
// whether it's still receiving data or not:
71+
const git: SimpleGit = simpleGit({
72+
timeout: {
73+
block: 5000,
74+
stdOut: false,
75+
stdErr: false
76+
}
77+
});
78+
```

docs/PLUGIN-UNSAFE-ACTIONS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ that any parameter sourced from user input is validated before being passed to t
66
In some cases where there is an elevated potential for harm `simple-git` will throw an exception unless you have
77
explicitly opted in to the potentially unsafe action.
88

9+
### Enabling custom upload and receive packs
10+
11+
Instead of using the default `git-receive-pack` and `git-upload-pack` binaries to parse incoming and outgoing
12+
data, `git` can be configured to use _any_ arbitrary binary or evaluable script.
13+
14+
To avoid accidentally triggering the evaluation of a malicious script when merging user provided parameters
15+
into command executed by `simple-git`, custom pack options (usually with the `--receive-pack` and `--upload-pack`)
16+
are blocked without explicitly opting into their use
17+
18+
```typescript
19+
import { simpleGit } from 'simple-git';
20+
21+
// throws
22+
await simpleGit()
23+
.raw('push', '--receive-pack=git-receive-pack-custom');
24+
25+
// allows calling clone with a helper transport
26+
await simpleGit({ unsafe: { allowUnsafePack: true } })
27+
.raw('push', '--receive-pack=git-receive-pack-custom');
28+
```
29+
930
### Overriding allowed protocols
1031

1132
A standard installation of `git` permits `file`, `http` and `ssh` protocols for a remote. A range of

examples/git-output-handler.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Output Handler
2+
3+
As `simple-git` receives data on either `stdout` or `stderr` streams from the `git`
4+
child processes it spawns, the data is buffered for parsing when the process has
5+
completed.
6+
7+
Add an `outputHandler` to the instance to pipe these streams to another target, for
8+
example piping to the main process `stdout` / `stderr`:
9+
10+
```typescript
11+
import { InitResult, SimpleGit, simpleGit } from "simple-git";
12+
13+
const git: SimpleGit = simpleGit()
14+
.outputHandler((_command, stdout, stderr) => {
15+
stdout.pipe(process.stdout);
16+
stderr.pipe(process.stderr);
17+
});
18+
19+
const init: InitResult = await git.init();
20+
```
21+
22+
Note: there is a single `outputHandler` per `simple-git` instance, calling the method again
23+
will overwrite the existing `outputHandler`.
24+
25+
Other uses for the `outputHandler` can include tracking the processes for metrics purposes,
26+
such as checking how many commands are currently being executed:
27+
28+
```typescript
29+
let processes = new Set();
30+
const currentlyRunning = () => processes.size;
31+
const git = context.git.outputHandler((_command, stdout, stderr) => {
32+
const start = new Date();
33+
const onClose = () => processes.delete(start);
34+
35+
stdout.on('close', onClose);
36+
stderr.on('close', onClose);
37+
38+
processes.add(start);
39+
});
40+
41+
expect(currentlyRunning()).toBe(0);
42+
const queue = [git.init(), git.add('*.txt')];
43+
44+
await wait(0);
45+
expect(currentlyRunning()).toBe(2);
46+
47+
await Promise.all(queue);
48+
expect(currentlyRunning()).toBe(0);
49+
```

packages/test-utils/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @simple-git/test-utils
22

3+
## 4.0.0
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [ec97a39]
8+
- Updated dependencies [97fde2c]
9+
- Updated dependencies [0a623e5]
10+
11+
312
## 3.0.0
413

514
### Patch Changes

packages/test-utils/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@simple-git/test-utils",
3-
"version": "3.0.0",
3+
"version": "4.0.0",
44
"private": true,
55
"peerDependencies": {
6-
"simple-git": "^3.15.0"
6+
"simple-git": "^3.19.1"
77
}
88
}

packages/test-utils/src/expectations.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export function assertGitError(
1717
errorConstructor: any = GitError
1818
) {
1919
expect(errorInstance).toBeInstanceOf(errorConstructor);
20-
expect(errorInstance).toHaveProperty('message', expect.stringMatching(message));
20+
expect(errorInstance).toHaveProperty(
21+
'message',
22+
typeof message === 'string'
23+
? expect.stringContaining(message)
24+
: expect.stringMatching(message)
25+
);
2126
}
2227

2328
export function assertGitResponseError(errorInstance: Error | unknown, git: any, equality?: any) {

simple-git/CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
# Change History & Release Notes
22

3+
## 3.19.1
4+
5+
### Patch Changes
6+
7+
- 2ab1936: keep path splitter without path specs
8+
9+
## 3.19.0
10+
11+
### Minor Changes
12+
13+
- f702b61: Create a utility to append pathspec / file lists to tasks through the TaskOptions array/object
14+
15+
## 3.18.0
16+
17+
### Minor Changes
18+
19+
- 5100f04: Add new interface for showBuffer to allow using `git show` on binary files.
20+
21+
### Patch Changes
22+
23+
- f54cd0d: Examples and documentation for outputHandler
24+
25+
## 3.17.0
26+
27+
### Minor Changes
28+
29+
- a63cfc2: Timeout plugin can now be configured to ignore data on either stdOut or stdErr in the git process when determining whether to kill the spawned process.
30+
31+
## 3.16.1
32+
33+
### Patch Changes
34+
35+
- 066b228: Fix overly permissive regex in push parser
36+
37+
## 3.16.0
38+
39+
### Minor Changes
40+
41+
- 97fde2c: Support the use of `-B` in place of the default `-b` in checkout methods
42+
- 0a623e5: Adds vulnerability detection to prevent use of `--upload-pack` and `--receive-pack` without explicitly opting in.
43+
44+
### Patch Changes
45+
46+
- ec97a39: Include restricting the use of git push --exec with other allowUnsafePack exclusions, thanks to @stsewd for the suggestion.
47+
348
## 3.15.1
449

550
### Patch Changes

simple-git/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "simple-git",
33
"description": "Simple GIT interface for node.js",
4-
"version": "3.15.1",
4+
"version": "3.19.1",
55
"author": "Steve King <[email protected]>",
66
"contributors": [
77
{
@@ -21,7 +21,6 @@
2121
"devDependencies": {
2222
"@kwsites/promise-result": "^1.1.0",
2323
"@simple-git/babel-config": "^1.0.0",
24-
"@simple-git/test-utils": "^3.0.0",
2524
"@types/debug": "^4.1.5",
2625
"@types/jest": "^29.2.2",
2726
"@types/node": "^16",

0 commit comments

Comments
 (0)