Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
actions
/
checkout
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
7739b9b
.github
.licenses
__test__
git-auth-helper.test.ts
git-command-manager.test.ts
git-directory-helper.test.ts
git-version.test.ts
input-helper.test.ts
modify-work-tree.sh
override-git-version.cmd
override-git-version.sh
ref-helper.test.ts
retry-helper.test.ts
verify-basic.sh
verify-clean.sh
verify-lfs.sh
verify-no-unstaged-changes.sh
verify-side-by-side.sh
verify-sparse-checkout-non-cone-mode.sh
verify-sparse-checkout.sh
verify-submodules-false.sh
verify-submodules-recursive.sh
verify-submodules-true.sh
adrs
dist
src
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.licensed.yml
.prettierignore
.prettierrc.json
CHANGELOG.md
CODEOWNERS
CONTRIBUTING.md
LICENSE
README.md
action.yml
jest.config.js
package-lock.json
package.json
tsconfig.json
Breadcrumbs
checkout
/
__test__
/
git-command-manager.test.ts
Blame
Blame
Latest commit
History
History
266 lines (229 loc) · 6.61 KB
Breadcrumbs
checkout
/
__test__
/
git-command-manager.test.ts
Top
File metadata and controls
Code
Blame
266 lines (229 loc) · 6.61 KB
Raw
import * as exec from '@actions/exec' import * as fshelper from '../lib/fs-helper' import * as commandManager from '../lib/git-command-manager' let git: commandManager.IGitCommandManager let mockExec = jest.fn() describe('git-auth-helper tests', () => { beforeAll(async () => {}) beforeEach(async () => { jest.spyOn(fshelper, 'fileExistsSync').mockImplementation(jest.fn()) jest.spyOn(fshelper, 'directoryExistsSync').mockImplementation(jest.fn()) }) afterEach(() => { jest.restoreAllMocks() }) afterAll(() => {}) it('branch list matches', async () => { mockExec.mockImplementation((path, args, options) => { console.log(args, options.listeners.stdout) if (args.includes('version')) { options.listeners.stdout(Buffer.from('2.18')) return 0 } if (args.includes('rev-parse')) { options.listeners.stdline(Buffer.from('refs/heads/foo')) options.listeners.stdline(Buffer.from('refs/heads/bar')) return 0 } return 1 }) jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) let branches = await git.branchList(false) expect(branches).toHaveLength(2) expect(branches.sort()).toEqual(['foo', 'bar'].sort()) }) it('ambiguous ref name output is captured', async () => { mockExec.mockImplementation((path, args, options) => { console.log(args, options.listeners.stdout) if (args.includes('version')) { options.listeners.stdout(Buffer.from('2.18')) return 0 } if (args.includes('rev-parse')) { options.listeners.stdline(Buffer.from('refs/heads/foo')) // If refs/tags/v1 and refs/heads/tags/v1 existed on this repository options.listeners.errline( Buffer.from("error: refname 'tags/v1' is ambiguous") ) return 0 } return 1 }) jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) let branches = await git.branchList(false) expect(branches).toHaveLength(1) expect(branches.sort()).toEqual(['foo'].sort()) }) }) describe('Test fetchDepth and fetchTags options', () => { beforeEach(async () => { jest.spyOn(fshelper, 'fileExistsSync').mockImplementation(jest.fn()) jest.spyOn(fshelper, 'directoryExistsSync').mockImplementation(jest.fn()) mockExec.mockImplementation((path, args, options) => { console.log(args, options.listeners.stdout) if (args.includes('version')) { options.listeners.stdout(Buffer.from('2.18')) } return 0 }) }) afterEach(() => { jest.restoreAllMocks() }) it('should call execGit with the correct arguments when fetchDepth is 0 and fetchTags is true', async () => { jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) const refSpec = ['refspec1', 'refspec2'] const options = { filter: 'filterValue', fetchDepth: 0, fetchTags: true } await git.fetch(refSpec, options) expect(mockExec).toHaveBeenCalledWith( expect.any(String), [ '-c', 'protocol.version=2', 'fetch', '--prune', '--progress', '--no-recurse-submodules', '--filter=filterValue', 'origin', 'refspec1', 'refspec2' ], expect.any(Object) ) }) it('should call execGit with the correct arguments when fetchDepth is 0 and fetchTags is false', async () => { jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) const refSpec = ['refspec1', 'refspec2'] const options = { filter: 'filterValue', fetchDepth: 0, fetchTags: false } await git.fetch(refSpec, options) expect(mockExec).toHaveBeenCalledWith( expect.any(String), [ '-c', 'protocol.version=2', 'fetch', '--no-tags', '--prune', '--progress', '--no-recurse-submodules', '--filter=filterValue', 'origin', 'refspec1', 'refspec2' ], expect.any(Object) ) }) it('should call execGit with the correct arguments when fetchDepth is 1 and fetchTags is false', async () => { jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) const refSpec = ['refspec1', 'refspec2'] const options = { filter: 'filterValue', fetchDepth: 1, fetchTags: false } await git.fetch(refSpec, options) expect(mockExec).toHaveBeenCalledWith( expect.any(String), [ '-c', 'protocol.version=2', 'fetch', '--no-tags', '--prune', '--progress', '--no-recurse-submodules', '--filter=filterValue', '--depth=1', 'origin', 'refspec1', 'refspec2' ], expect.any(Object) ) }) it('should call execGit with the correct arguments when fetchDepth is 1 and fetchTags is true', async () => { jest.spyOn(exec, 'exec').mockImplementation(mockExec) const workingDirectory = 'test' const lfs = false const doSparseCheckout = false git = await commandManager.createCommandManager( workingDirectory, lfs, doSparseCheckout ) const refSpec = ['refspec1', 'refspec2'] const options = { filter: 'filterValue', fetchDepth: 1, fetchTags: true } await git.fetch(refSpec, options) expect(mockExec).toHaveBeenCalledWith( expect.any(String), [ '-c', 'protocol.version=2', 'fetch', '--prune', '--progress', '--no-recurse-submodules', '--filter=filterValue', '--depth=1', 'origin', 'refspec1', 'refspec2' ], expect.any(Object) ) }) })
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
You can’t perform that action at this time.