-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
pull-fails-ff.spec.ts
87 lines (68 loc) · 2.92 KB
/
pull-fails-ff.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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),
}))
});
});