FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/test/tests/clone.js at master · nodegit/nodegit · GitHub
nodegit
nodegit
Repository navigation
Code
Issues
344
(344)
Pull requests
21
(21)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
test
/
tests
/
clone.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
359 lines (321 loc) · 9.91 KB
Breadcrumbs
nodegit
/
test
/
tests
/
clone.js
Copy path
File metadata and controls
359 lines (321 loc) · 9.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
var
path
=
require
(
"path"
)
;
var
assert
=
require
(
"assert"
)
;
var
fse
=
require
(
"fs-extra"
)
;
var
local
=
path
.
join
.
bind
(
path
,
__dirname
)
;
var
_
=
require
(
"lodash"
)
;
const
generatePathWithLength
=
(
base
,
length
)
=>
{
let
path
=
`
${
base
}
/`
;
const
baseLength
=
path
.
length
;
const
remaining
=
length
-
baseLength
;
for
(
let
i
=
0
;
i
<
remaining
;
++
i
)
{
// add a slash every 240 characters, but not as first or last character
if
(
i
%
239
==
0
&&
i
!=
remaining
-
1
&&
i
!=
0
)
{
path
+=
"/"
;
}
else
{
path
+=
"a"
;
}
}
assert
.
ok
(
path
.
length
===
length
)
;
return
path
;
}
;
describe
(
"Clone"
,
function
(
)
{
var
NodeGit
=
require
(
"../../"
)
;
var
Repository
=
NodeGit
.
Repository
;
var
Clone
=
NodeGit
.
Clone
;
var
clonePath
=
local
(
"../repos/clone"
)
;
var
longClonePath
=
generatePathWithLength
(
clonePath
,
600
)
;
var
sshPublicKeyPath
=
local
(
"../id_rsa.pub"
)
;
var
sshPrivateKeyPath
=
local
(
"../id_rsa"
)
;
var
sshEncryptedPublicKeyPath
=
local
(
"../encrypted_rsa.pub"
)
;
var
sshEncryptedPrivateKeyPath
=
local
(
"../encrypted_rsa"
)
;
// Set a reasonable timeout here now that our repository has grown.
this
.
timeout
(
30000
)
;
beforeEach
(
function
(
)
{
return
fse
.
remove
(
clonePath
)
.
then
(
function
(
)
{
return
fse
.
remove
(
longClonePath
)
;
}
)
.
catch
(
function
(
err
)
{
console
.
log
(
err
)
;
throw
err
;
}
)
;
}
)
;
it
.
skip
(
"can clone with http"
,
function
(
)
{
var
test
=
this
;
var
url
=
"http://git.tbranyen.com/smart/site-content"
;
return
Clone
(
url
,
clonePath
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone with https"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone twice with https using same config object"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
progressCount
=
0
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
transferProgress
:
function
(
progress
)
{
progressCount
++
;
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
assert
.
notEqual
(
progressCount
,
0
)
;
return
fse
.
remove
(
clonePath
)
;
}
)
.
then
(
function
(
)
{
progressCount
=
0
;
return
Clone
(
url
,
clonePath
,
opts
)
;
}
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
assert
.
notEqual
(
progressCount
,
0
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
function
updateProgressIntervals
(
progressIntervals
,
lastInvocation
)
{
var
now
=
new
Date
(
)
;
if
(
lastInvocation
)
{
progressIntervals
.
push
(
now
-
lastInvocation
)
;
}
return
now
;
}
it
(
"can clone with https and default throttled progress"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
progressCount
=
0
;
var
lastInvocation
;
var
progressIntervals
=
[
]
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
transferProgress
:
function
(
progress
)
{
lastInvocation
=
updateProgressIntervals
(
progressIntervals
,
lastInvocation
)
;
progressCount
++
;
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
assert
.
notEqual
(
progressCount
,
0
)
;
var
averageProgressInterval
=
_
.
sum
(
progressIntervals
)
/
progressIntervals
.
length
;
// even though we are specifying a throttle period of 100,
// the throttle is applied on the scheduling side,
// and actual execution is at the mercy of the main js thread
// so the actual throttle intervals could be less than the specified
// throttle period
if
(
!
averageProgressInterval
||
averageProgressInterval
<
75
)
{
assert
.
fail
(
averageProgressInterval
,
75
,
"unexpected average time between callbacks"
,
"<"
)
;
}
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone with https and explicitly throttled progress"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
progressCount
=
0
;
var
lastInvocation
;
var
progressIntervals
=
[
]
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
transferProgress
:
{
throttle
:
50
,
callback
:
function
(
progress
)
{
lastInvocation
=
updateProgressIntervals
(
progressIntervals
,
lastInvocation
)
;
progressCount
++
;
}
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
assert
.
notEqual
(
progressCount
,
0
)
;
var
averageProgressInterval
=
_
.
sum
(
progressIntervals
)
/
progressIntervals
.
length
;
if
(
!
averageProgressInterval
||
averageProgressInterval
<
35
)
{
assert
.
fail
(
averageProgressInterval
,
35
,
"unexpected average time between callbacks"
,
"<"
)
;
}
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone without waiting for callback results"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
lastReceivedObjects
=
0
;
var
cloneFinished
=
false
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
transferProgress
:
{
waitForResult
:
false
,
callback
:
function
(
progress
)
{
var
receivedObjects
=
progress
.
receivedObjects
(
)
;
assert
.
false
(
cloneFinished
,
"callback running after clone completion"
)
;
assert
.
gt
(
receivedObjects
,
lastReceivedObjects
)
;
lastReceivedObjects
=
receivedObjects
;
}
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
cloneFinished
=
true
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone using nested function"
,
function
(
)
{
var
test
=
this
;
var
url
=
"https://github.com/nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
}
}
}
;
return
Clone
.
clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone with ssh"
,
function
(
)
{
var
test
=
this
;
var
url
=
"git@github.com:nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
,
credentials
:
function
(
url
,
userName
)
{
return
NodeGit
.
Credential
.
sshKeyFromAgent
(
userName
)
;
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone with ssh while manually loading a key"
,
function
(
)
{
var
test
=
this
;
var
url
=
"git@github.com:nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
,
credentials
:
function
(
url
,
userName
)
{
return
NodeGit
.
Credential
.
sshKeyNew
(
userName
,
sshPublicKeyPath
,
sshPrivateKeyPath
,
""
)
;
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"can clone with ssh while manually loading an encrypted key"
,
function
(
)
{
var
test
=
this
;
var
url
=
"git@github.com:nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
,
credentials
:
function
(
url
,
userName
)
{
return
NodeGit
.
Credential
.
sshKeyNew
(
userName
,
sshEncryptedPublicKeyPath
,
sshEncryptedPrivateKeyPath
,
"test-password"
)
;
}
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
// Since 15 March the unauthenticated git protocol on port 9418 is no longer supported in Github.
// https://github.blog/2021-09-01-improving-git-protocol-security-github/
it
.
skip
(
"can clone with git"
,
function
(
)
{
var
test
=
this
;
var
url
=
"git://github.com/nodegit/test.git"
;
var
opts
=
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
}
}
}
;
return
Clone
(
url
,
clonePath
,
opts
)
.
then
(
function
(
repo
)
{
test
.
repository
=
repo
;
assert
.
ok
(
repo
instanceof
Repository
)
;
}
)
;
}
)
;
it
(
"can clone with filesystem"
,
function
(
)
{
var
test
=
this
;
var
prefix
=
process
.
platform
===
"win32"
?
""
:
"file://"
;
var
url
=
prefix
+
local
(
"../repos/empty"
)
;
return
Clone
(
url
,
clonePath
)
.
then
(
function
(
repo
)
{
assert
.
ok
(
repo
instanceof
Repository
)
;
test
.
repository
=
repo
;
}
)
;
}
)
;
it
(
"will not segfault when accessing a url without username"
,
function
(
)
{
var
url
=
"https://github.com/nodegit/private"
;
var
firstPass
=
true
;
return
Clone
(
url
,
clonePath
,
{
fetchOpts
:
{
callbacks
:
{
certificateCheck
:
(
)
=>
0
,
credentials
:
function
(
)
{
if
(
firstPass
)
{
firstPass
=
false
;
return
NodeGit
.
Credential
.
userpassPlaintextNew
(
"fake-token"
,
"x-oauth-basic"
)
;
}
else
{
return
NodeGit
.
Credential
.
defaultNew
(
)
;
}
}
}
}
}
)
.
catch
(
function
(
reason
)
{
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL