-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support parsing empty responses
fix: support parsing empty responses - parsers should treat `undefined` in either `stdout` or `stderr` the same as an empty string fix: detect fatal exceptions in `git pull` - In the case that a `git pull` fails with a recognised fatal error (eg: a `--ff-only` pull cannot be fast-forwarded), the exception thrown will be a `GitResponseError<PullFailedResult>` with summary details of the exception rather than a standard process terminated exception Closes #713
- Loading branch information
Showing
9 changed files
with
162 additions
and
7 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
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,87 @@ | ||
import { promiseError } from '@kwsites/promise-result'; | ||
import { GitResponseError, PullFailedResult } from '../../typings'; | ||
import { createTestContext, like, newSimpleGit, setUpInit, SimpleGitTestContext } from '../__fixtures__'; | ||
|
||
describe('pull --ff-only', () => { | ||
let context: SimpleGitTestContext; | ||
|
||
beforeEach(async () => context = await createTestContext()); | ||
beforeEach(async () => { | ||
const upstream = await context.dir('upstream'); | ||
const local = context.path('local'); | ||
await context.file(['upstream', 'file']); | ||
|
||
await givenRemote(upstream); | ||
await givenLocal(upstream, local); | ||
}); | ||
|
||
async function givenLocal(upstream: string, local: string) { | ||
await newSimpleGit(context.root).clone(upstream, local); | ||
await setUpInit({git: newSimpleGit(local)}); | ||
} | ||
|
||
async function givenRemote(upstream: string) { | ||
const git = newSimpleGit(upstream); | ||
await setUpInit({git}); | ||
await git.add('.'); | ||
await git.commit('first'); | ||
} | ||
|
||
async function givenRemoteFileChanged() { | ||
await context.file(['upstream', 'file'], 'new remote file content'); | ||
await newSimpleGit(context.path('upstream')).add('.').commit('remote updated'); | ||
} | ||
|
||
async function givenLocalFileChanged() { | ||
await context.file(['local', 'file'], 'new local file content'); | ||
await newSimpleGit(context.path('local')).add('.').commit('local updated'); | ||
} | ||
|
||
it('allows fast-forward when there are no changes local or remote', async () => { | ||
const git = newSimpleGit(context.path('local')); | ||
const result = await git.pull(['--ff-only']); | ||
|
||
expect(result.files).toEqual([]); | ||
}); | ||
|
||
it('allows fast-forward when there are some remote but no local changes', async () => { | ||
await givenRemoteFileChanged(); | ||
|
||
const git = newSimpleGit(context.path('local')); | ||
const result = await git.pull(['--ff-only']); | ||
|
||
expect(result.files).toEqual(['file']); | ||
}); | ||
|
||
it('allows fast-forward when there are no remote but some local changes', async () => { | ||
await givenLocalFileChanged(); | ||
|
||
const git = newSimpleGit(context.path('local')); | ||
const result = await git.pull(['--ff-only']); | ||
|
||
expect(result.files).toEqual([]); | ||
}); | ||
|
||
it('fails fast-forward when there are both remote and local changes', async () => { | ||
await givenLocalFileChanged(); | ||
await givenRemoteFileChanged(); | ||
|
||
const git = newSimpleGit(context.path('local')); | ||
const err = await promiseError<GitResponseError<PullFailedResult>>(git.pull(['--ff-only'])); | ||
|
||
expect(err?.git.message).toMatch('Not possible to fast-forward, aborting'); | ||
expect(err?.git).toEqual(like({ | ||
remote: context.path('upstream'), | ||
hash: { | ||
local: expect.any(String), | ||
remote: expect.any(String), | ||
}, | ||
branch: { | ||
local: expect.any(String), | ||
remote: expect.any(String), | ||
}, | ||
message: String(err?.git), | ||
})) | ||
}); | ||
|
||
}); |
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