FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/lib/commit.js at master · nodegit/nodegit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
nodegit
/
nodegit
Public
Notifications
You must be signed in to change notification settings
Fork
700
Star
5.8k
Code
Issues
343
Pull requests
20
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
lib
/
commit.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
437 lines (392 loc) · 10.2 KB
Breadcrumbs
nodegit
/
lib
/
commit.js
Copy path
File metadata and controls
437 lines (392 loc) · 10.2 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
var
events
=
require
(
"events"
)
;
var
fp
=
require
(
"lodash/fp"
)
;
var
NodeGit
=
require
(
"../"
)
;
var
Commit
=
NodeGit
.
Commit
;
var
LookupWrapper
=
NodeGit
.
Utils
.
lookupWrapper
;
var
_amend
=
Commit
.
prototype
.
amend
;
var
_parent
=
Commit
.
prototype
.
parent
;
/**
* Retrieves the commit pointed to by the oid
*
@async
*
@param
{
Repository
} repo The repo that the commit lives in
*
@param
{
String|Oid|Commit
} id The commit to lookup
*
@return
{
Commit
}
*/
Commit
.
lookup
=
LookupWrapper
(
Commit
)
;
/**
*
@async
*
@param
{
Number
} n
*
@return
{
Commit
}
*/
Commit
.
prototype
.
parent
=
function
(
n
)
{
var
repo
=
this
.
repo
;
return
_parent
.
call
(
this
,
n
)
.
then
(
p
=>
{
p
.
repo
=
repo
;
return
p
;
}
)
;
}
;
/**
* Amend a commit
*
@async
*
@param
{
String
} update_ref
*
@param
{
Signature
} author
*
@param
{
Signature
} committer
*
@param
{
String
} message_encoding
*
@param
{
String
} message
*
@param
{
Tree|Oid
} tree
*
@return
{
Oid
}
*/
Commit
.
prototype
.
amend
=
function
(
updateRef
,
author
,
committer
,
message_encoding
,
message
,
tree
)
{
var
repo
=
this
.
repo
;
var
_this
=
this
;
var
treePromise
;
if
(
tree
instanceof
NodeGit
.
Oid
)
{
treePromise
=
repo
.
getTree
(
tree
)
;
}
else
{
treePromise
=
Promise
.
resolve
(
tree
)
;
}
return
treePromise
.
then
(
function
(
treeObject
)
{
return
_amend
.
call
(
_this
,
updateRef
,
author
,
committer
,
message_encoding
,
message
,
treeObject
)
;
}
)
;
}
;
/**
* Amend a commit with the given signature
*
@async
*
@param
{
String
} updateRef
*
@param
{
Signature
} author
*
@param
{
Signature
} committer
*
@param
{
String
} messageEncoding
*
@param
{
String
} message
*
@param
{
Tree|Oid
} tree
*
@param
{
Function
} onSignature Callback to be called with string to be signed
*
@return
{
Oid
}
*/
Commit
.
prototype
.
amendWithSignature
=
function
(
updateRef
,
author
,
committer
,
messageEncoding
,
message
,
tree
,
onSignature
)
{
let
repo
=
this
.
repo
;
let
parentOids
=
this
.
parents
(
)
;
let
_this
=
this
;
let
promises
=
[
]
;
if
(
tree
instanceof
NodeGit
.
Oid
)
{
promises
.
push
(
repo
.
getTree
(
tree
)
)
;
}
else
{
promises
.
push
(
Promise
.
resolve
(
tree
)
)
;
}
parentOids
.
forEach
(
function
(
parentOid
)
{
promises
.
push
(
repo
.
getCommit
(
parentOid
)
)
;
}
)
;
let
treeObject
;
let
parents
;
let
commitContent
;
let
commit
;
let
skippedSigning
;
let
resolvedAuthor
;
let
resolvedCommitter
;
let
resolvedMessageEncoding
;
let
resolvedMessage
;
let
resolvedTree
;
let
createCommitPromise
=
Promise
.
all
(
promises
)
.
then
(
function
(
results
)
{
treeObject
=
fp
.
head
(
results
)
;
parents
=
fp
.
tail
(
results
)
;
return
_this
.
getTree
(
)
;
}
)
.
then
(
function
(
commitTreeResult
)
{
let
commitTree
=
commitTreeResult
;
let
truthyArgs
=
fp
.
omitBy
(
fp
.
isNil
,
{
author
,
committer
,
messageEncoding
,
message
,
tree
:
treeObject
}
)
;
let
commitFields
=
{
author
:
_this
.
author
(
)
,
committer
:
_this
.
committer
(
)
,
messageEncoding
:
_this
.
messageEncoding
(
)
,
message
:
_this
.
message
(
)
,
tree
:
commitTree
}
;
(
{
author
:
resolvedAuthor
,
committer
:
resolvedCommitter
,
messageEncoding
:
resolvedMessageEncoding
,
message
:
resolvedMessage
,
tree
:
resolvedTree
}
=
fp
.
assign
(
commitFields
,
truthyArgs
)
)
;
return
Commit
.
createBuffer
(
repo
,
resolvedAuthor
,
resolvedCommitter
,
resolvedMessageEncoding
,
resolvedMessage
,
resolvedTree
,
parents
.
length
,
parents
)
;
}
)
.
then
(
function
(
commitContentResult
)
{
commitContent
=
commitContentResult
;
if
(
!
commitContent
.
endsWith
(
"\n"
)
)
{
commitContent
+=
"\n"
;
}
return
onSignature
(
commitContent
)
;
}
)
.
then
(
function
(
{
code
,
field
,
signedData
}
)
{
switch
(
code
)
{
case
NodeGit
.
Error
.
CODE
.
OK
:
return
Commit
.
createWithSignature
(
repo
,
commitContent
,
signedData
,
field
)
;
case
NodeGit
.
Error
.
CODE
.
PASSTHROUGH
:
skippedSigning
=
true
;
return
Commit
.
create
(
repo
,
updateRef
,
resolvedAuthor
,
resolvedCommitter
,
resolvedMessageEncoding
,
resolvedMessage
,
resolvedTree
,
parents
.
length
,
parents
)
;
default
:
{
const
error
=
new
Error
(
`Commit.amendWithSignature threw with error code
${
code
}
`
)
;
error
.
errno
=
code
;
throw
error
;
}
}
}
)
;
if
(
!
updateRef
)
{
return
createCommitPromise
;
}
return
createCommitPromise
.
then
(
function
(
commitOid
)
{
if
(
skippedSigning
)
{
return
commitOid
;
}
return
repo
.
getCommit
(
commitOid
)
.
then
(
function
(
commitResult
)
{
commit
=
commitResult
;
return
repo
.
getReference
(
updateRef
)
;
}
)
.
then
(
function
(
ref
)
{
return
ref
.
setTarget
(
commitOid
,
`commit (amend):
${
commit
.
summary
(
)
}
`
)
;
}
)
.
then
(
function
(
)
{
return
commitOid
;
}
)
;
}
)
;
}
;
/**
* Retrieve the commit time as a Date object.
*
@return
{
Date
}
*/
Commit
.
prototype
.
date
=
function
(
)
{
return
new
Date
(
this
.
timeMs
(
)
)
;
}
;
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
*
@async
*
@return
{
Array<Diff>
} an array of diffs
*/
Commit
.
prototype
.
getDiff
=
function
(
)
{
return
this
.
getDiffWithOptions
(
null
)
;
}
;
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
*
@async
*
@param
{
Object
} options
*
@return
{
Array<Diff>
} an array of diffs
*/
Commit
.
prototype
.
getDiffWithOptions
=
function
(
options
)
{
var
commit
=
this
;
return
commit
.
getTree
(
)
.
then
(
function
(
thisTree
)
{
return
commit
.
getParents
(
)
.
then
(
function
(
parents
)
{
var
diffs
;
if
(
parents
.
length
)
{
diffs
=
parents
.
map
(
function
(
parent
)
{
return
parent
.
getTree
(
)
.
then
(
function
(
parentTree
)
{
return
thisTree
.
diffWithOptions
(
parentTree
,
options
)
;
}
)
;
}
)
;
}
else
{
diffs
=
[
thisTree
.
diffWithOptions
(
null
,
options
)
]
;
}
return
Promise
.
all
(
diffs
)
;
}
)
;
}
)
;
}
;
/**
* Retrieve the entry represented by path for this commit.
* Path must be relative to repository root.
*
*
@async
*
@param
{
String
} path
*
@return
{
TreeEntry
}
*/
Commit
.
prototype
.
getEntry
=
function
(
path
)
{
return
this
.
getTree
(
)
.
then
(
function
(
tree
)
{
return
tree
.
getEntry
(
path
)
;
}
)
;
}
;
/**
* Retrieve the commit's parents as commit objects.
*
*
@async
*
@param
{
number
} limit Optional amount of parents to return.
*
@return
{
Array<Commit>
} array of commits
*/
Commit
.
prototype
.
getParents
=
function
(
limit
)
{
var
parents
=
[
]
;
// If no limit was set, default to the maximum parents.
limit
=
typeof
limit
===
"number"
?
limit
:
this
.
parentcount
(
)
;
limit
=
Math
.
min
(
limit
,
this
.
parentcount
(
)
)
;
for
(
var
i
=
0
;
i
<
limit
;
i
++
)
{
var
oid
=
this
.
parentId
(
i
)
;
var
parent
=
this
.
repo
.
getCommit
(
oid
)
;
parents
.
push
(
parent
)
;
}
// Wait for all parents to complete, before returning.
return
Promise
.
all
(
parents
)
;
}
;
/**
*
@typedef
extractedSignature
*
@type
{
Object
}
*
@property
{
String
} signature the signature of the commit
*
@property
{
String
} signedData the extracted signed data
*/
/**
* Retrieve the signature and signed data for a commit.
*
@param
{
String
} field Optional field to get from the signature,
* defaults to gpgsig
*
@return
{
extractedSignature
}
*/
Commit
.
prototype
.
getSignature
=
function
(
field
)
{
return
Commit
.
extractSignature
(
this
.
repo
,
this
.
id
(
)
,
field
)
;
}
;
/**
* Get the tree associated with this commit.
*
*
@async
*
@return
{
Tree
}
*/
Commit
.
prototype
.
getTree
=
function
(
)
{
return
this
.
repo
.
getTree
(
this
.
treeId
(
)
)
;
}
;
/**
* Walk the history from this commit backwards.
*
* An EventEmitter is returned that will emit a "commit" event for each
* commit in the history, and one "end" event when the walk is completed.
* Don't forget to call `start()` on the returned event.
*
*
@fires
EventEmitter#commit Commit
*
@fires
EventEmitter#end Array<Commit>
*
@fires
EventEmitter#error Error
*
*
@return
{
EventEmitter
}
*
@start
start()
*/
Commit
.
prototype
.
history
=
function
(
)
{
var
event
=
new
events
.
EventEmitter
(
)
;
var
oid
=
this
.
id
(
)
;
var
revwalk
=
this
.
repo
.
createRevWalk
(
)
;
revwalk
.
sorting
.
apply
(
revwalk
,
arguments
)
;
var
commits
=
[
]
;
event
.
start
=
function
(
)
{
revwalk
.
walk
(
oid
,
function
commitRevWalk
(
error
,
commit
)
{
if
(
error
)
{
if
(
error
.
errno
===
NodeGit
.
Error
.
CODE
.
ITEROVER
)
{
event
.
emit
(
"end"
,
commits
)
;
return
;
}
else
{
return
event
.
emit
(
"error"
,
error
)
;
}
}
event
.
emit
(
"commit"
,
commit
)
;
commits
.
push
(
commit
)
;
}
)
;
}
;
return
event
;
}
;
/**
* Get the specified parent of the commit.
*
*
@param
{
number
} the position of the parent, starting from 0
*
@async
*
@return
{
Commit
} the parent commit at the specified position
*/
Commit
.
prototype
.
parent
=
function
(
id
)
{
var
repository
=
this
.
repo
;
return
_parent
.
call
(
this
,
id
)
.
then
(
function
(
parent
)
{
parent
.
repo
=
repository
;
return
parent
;
}
)
;
}
;
/**
* Retrieve the commit's parent shas.
*
*
@return
{
Array<Oid>
} array of oids
*/
Commit
.
prototype
.
parents
=
function
(
)
{
var
result
=
[
]
;
for
(
var
i
=
0
;
i
<
this
.
parentcount
(
)
;
i
++
)
{
result
.
push
(
this
.
parentId
(
i
)
)
;
}
return
result
;
}
;
/**
* Retrieve the SHA.
*
@return
{
String
}
*/
Commit
.
prototype
.
sha
=
function
(
)
{
return
this
.
id
(
)
.
toString
(
)
;
}
;
/**
* Retrieve the commit time as a unix timestamp.
*
@return
{
Number
}
*/
Commit
.
prototype
.
timeMs
=
function
(
)
{
return
this
.
time
(
)
*
1000
;
}
;
/**
* The sha of this commit
*
@return
{
String
}
*/
Commit
.
prototype
.
toString
=
function
(
)
{
return
this
.
sha
(
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL