FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/lib/commit.js at master · daxelrod/nodegit · GitHub
daxelrod
nodegit
Repository navigation
Code
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
258 lines (224 loc) · 5.76 KB
Breadcrumbs
nodegit
/
lib
/
commit.js
Copy path
File metadata and controls
258 lines (224 loc) · 5.76 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
var
events
=
require
(
"events"
)
;
var
Promise
=
require
(
"nodegit-promise"
)
;
var
NodeGit
=
require
(
"../"
)
;
var
Commit
=
NodeGit
.
Commit
;
var
LookupWrapper
=
NodeGit
.
Utils
.
lookupWrapper
;
/**
* 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
)
;
/**
* 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
;
}
;
/**
* Retrieve the commit time as a Date object.
*
@return
{
Date
}
*/
Commit
.
prototype
.
date
=
function
(
)
{
return
new
Date
(
this
.
timeMs
(
)
)
;
}
;
/**
* Get the tree associated with this commit.
*
*
@async
*
@return
{
Tree
}
*/
Commit
.
prototype
.
getTree
=
function
(
callback
)
{
return
this
.
repo
.
getTree
(
this
.
treeId
(
)
,
callback
)
;
}
;
/**
* 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
,
callback
)
{
return
this
.
getTree
(
)
.
then
(
function
(
tree
)
{
return
tree
.
getEntry
(
path
)
.
then
(
function
(
entry
)
{
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
entry
)
;
}
return
entry
;
}
)
;
}
,
callback
)
;
}
;
/**
* 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
;
}
;
/**
* Retrieve the commit's parents as commit objects.
*
*
@async
*
@param
{
number
} limit Optional amount of parents to return.
*
@param
{
Function
} callback
*
@return
{
Array<Commit>
} array of commits
*/
Commit
.
prototype
.
getParents
=
function
(
limit
,
callback
)
{
var
parents
=
[
]
;
// Shift arguments.
if
(
typeof
limit
===
"function"
)
{
callback
=
limit
;
}
// 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
)
.
then
(
function
(
parents
)
{
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
parents
)
;
}
return
parents
;
}
,
callback
)
;
}
;
/**
* Retrieve the commit"s parent shas.
*
*
@param
{
Function
} callback
*
@return
{
Array<Oids>
} array of oids
*/
Commit
.
prototype
.
parents
=
function
(
)
{
var
result
=
[
]
;
for
(
var
i
=
0
;
i
<
this
.
parentcount
(
)
;
i
++
)
{
result
.
push
(
this
.
parentId
(
i
)
)
;
}
return
result
;
}
;
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
*
@async
*
@param
{
Function
} callback
*
@return
{
Array<Diff>
} an array of diffs
*/
Commit
.
prototype
.
getDiff
=
function
(
callback
)
{
return
this
.
getDiffWithOptions
(
null
,
callback
)
;
}
;
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
*
@async
*
@param
{
Object
} options
*
@param
{
Function
} callback
*
@return
{
Array<Diff>
} an array of diffs
*/
Commit
.
prototype
.
getDiffWithOptions
=
function
(
options
,
callback
)
{
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
.
diff
(
null
)
]
;
}
return
Promise
.
all
(
diffs
)
;
}
)
;
}
)
.
then
(
function
(
diffs
)
{
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
diffs
)
;
}
return
diffs
;
}
,
callback
)
;
}
;
/**
* 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
*
@param
{
Oid
} callback
*/
var
amend
=
Commit
.
prototype
.
amend
;
Commit
.
prototype
.
amend
=
function
(
updateRef
,
author
,
committer
,
message_encoding
,
message
,
tree
,
callback
)
{
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
)
;
}
)
;
}
;
/**
* The sha of this commit
*
@return
{
String
}
*/
Commit
.
prototype
.
toString
=
function
(
)
{
return
this
.
sha
(
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL