-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpull.test.ts
144 lines (123 loc) · 3.98 KB
/
pull.test.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { pull, log, add, commit } from 'git-essentials'
import { setGitClientAgent } from 'git-essentials/utils/pkg'
import { FastForwardError } from 'git-essentials/errors'
import { FsFixtureData, makeFsFixture } from './helpers/makeFsFixture'
import { makeHttpFixture, HttpFixtureData } from './helpers/makeHttpFixture'
import { expectToFailWithTypeAsync } from './helpers/assertionHelper'
import pullFsFixtureData from './fixtures/fs/pull.json'
import pullNoFfFsFixtureData from './fixtures/fs/pull-no-ff.json'
import pullHttpFixtureData from './fixtures/http/pull.json'
describe('pull', () => {
beforeEach(() => {
// The default agent string is version depended.
// We need to set version independent variant to make sure HttpFixtures will work.
setGitClientAgent('git/git-essentials')
})
it('pull', async () => {
// arrange
const { fs, dir } = await makeFsFixture(pullFsFixtureData as FsFixtureData)
const http = makeHttpFixture(pullHttpFixtureData as HttpFixtureData)
// act
let logs = await log({ fs, dir, ref: 'refs/heads/main' })
// assert
expect(logs.map(({ commit }) => commit.message)).toEqual([
'Initial commit\n',
])
// act
await pull({
fs,
http,
dir,
remote: 'origin',
ref: 'refs/heads/main',
author: {
name: 'Mr. Test',
email: 'mrtest@example.com',
timestamp: 1262356920,
timezoneOffset: -0,
},
})
logs = await log({ fs, dir, ref: 'refs/heads/main' })
// assert
expect(logs.map(({ commit }) => commit.message)).toEqual([
'Added c.txt\n',
'Added b.txt\n',
'Initial commit\n',
])
})
it('pull fast-forward only', async () => {
// arrange
const author = {
name: 'Mr. Test',
email: 'mrtest@example.com',
timestamp: 1262356920,
timezoneOffset: -0,
}
const { fs, dir } = await makeFsFixture(pullNoFfFsFixtureData as FsFixtureData)
const http = makeHttpFixture(pullHttpFixtureData as HttpFixtureData)
// act
await fs.writeFile(`${dir}/z.txt`, 'Hi')
await add({ fs, dir, filepath: 'z.txt' })
await commit({ fs, dir, message: 'Added z.txt', author })
const logs = await log({ fs, dir, ref: 'refs/heads/main' })
// assert
expect(logs.map(({ commit }) => commit.message)).toEqual([
'Added z.txt\n',
'Initial commit\n',
])
// act
const action = async () => {
await pull({
fs,
http,
dir,
remote: 'origin',
ref: 'refs/heads/main',
fastForwardOnly: true,
author: {
name: 'Mr. Test',
email: 'mrtest@example.com',
timestamp: 1262356920,
timezoneOffset: -0,
},
})
}
// assert
await expectToFailWithTypeAsync(action, FastForwardError)
})
it('pull no fast-forward', async () => {
// arrange
const { fs, dir } = await makeFsFixture(pullNoFfFsFixtureData as FsFixtureData)
const http = makeHttpFixture(pullHttpFixtureData as HttpFixtureData)
// act
let logs = await log({ fs, dir, ref: 'refs/heads/main' })
expect(logs.map(({ commit }) => commit.message)).toEqual([
'Initial commit\n',
])
await pull({
fs,
http,
dir,
remote: 'origin',
ref: 'refs/heads/main',
fastForward: false,
author: {
name: 'Mr. Test',
email: 'mrtest@example.com',
timestamp: 1262356920,
timezoneOffset: -0,
},
})
logs = await log({ fs, dir, ref: 'refs/heads/main' })
const formattedLogs = logs.map(
({ commit }) => `${commit.message} (${commit.parent.join(' ')})`
)
// assert
expect(formattedLogs).toEqual([
"Merge branch 'main' of http://localhost/pull-server.git\n (5a8905a02e181fe1821068b8c0f48cb6633d5b81 97c024f73eaab2781bf3691597bc7c833cb0e22f)",
'Added c.txt\n (c82587c97be8f9a10088590e06c9d0f767ed5c4a)',
'Added b.txt\n (5a8905a02e181fe1821068b8c0f48cb6633d5b81)',
'Initial commit\n ()',
])
})
})