FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/test/tests/commit.js at v0.2.5 · 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
/
commit.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
278 lines (227 loc) · 6.89 KB
Breadcrumbs
nodegit
/
test
/
tests
/
commit.js
Copy path
File metadata and controls
278 lines (227 loc) · 6.89 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
var
assert
=
require
(
"assert"
)
;
var
path
=
require
(
"path"
)
;
var
Promise
=
require
(
"nodegit-promise"
)
;
var
promisify
=
require
(
"promisify-node"
)
;
var
fse
=
promisify
(
require
(
"fs-extra"
)
)
;
var
NodeGit
=
require
(
"../../"
)
;
var
Repository
=
NodeGit
.
Repository
;
describe
(
"Commit"
,
function
(
)
{
var
reposPath
=
path
.
resolve
(
"test/repos/workdir/.git"
)
;
var
oid
=
"fce88902e66c72b5b93e75bdb5ae717038b221f6"
;
beforeEach
(
function
(
)
{
var
test
=
this
;
return
Repository
.
open
(
reposPath
)
.
then
(
function
(
repository
)
{
test
.
repository
=
repository
;
return
repository
.
getCommit
(
oid
)
.
then
(
function
(
commit
)
{
test
.
commit
=
commit
;
}
)
;
}
)
;
}
)
;
it
(
"will fail with an invalid sha"
,
function
(
)
{
return
this
.
repository
.
getCommit
(
"invalid"
)
.
then
(
null
,
function
(
err
)
{
assert
.
ok
(
err
instanceof
Error
)
;
}
)
;
}
)
;
it
(
"has a message"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
message
(
)
,
"Update README.md"
)
;
}
)
;
it
(
"has a raw message"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
messageRaw
(
)
,
"Update README.md"
)
;
}
)
;
it
(
"has a message encoding"
,
function
(
)
{
var
encoding
=
this
.
commit
.
messageEncoding
(
)
;
assert
.
ok
(
encoding
===
"UTF-8"
||
encoding
===
undefined
)
;
}
)
;
it
(
"has a summary"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
summary
(
)
,
"Update README.md"
)
;
}
)
;
it
(
"has a sha"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
sha
(
)
,
oid
)
;
}
)
;
it
(
"has a time"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
timeMs
(
)
,
1362012884000
)
;
}
)
;
it
(
"has a date"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
date
(
)
.
getTime
(
)
,
1362012884000
)
;
}
)
;
it
(
"has a time offset"
,
function
(
)
{
assert
.
equal
(
this
.
commit
.
timeOffset
(
)
,
780
)
;
}
)
;
it
(
"can create a commit"
,
function
(
)
{
var
expectedCommitId
=
"315e77328ef596f3bc065d8ac6dd2c72c09de8a5"
;
var
fileName
=
"newfile.txt"
;
var
fileContent
=
"hello world"
;
var
repo
;
var
index
;
var
treeOid
;
var
parent
;
return
NodeGit
.
Repository
.
open
(
reposPath
)
.
then
(
function
(
repoResult
)
{
repo
=
repoResult
;
return
fse
.
writeFile
(
path
.
join
(
repo
.
workdir
(
)
,
fileName
)
,
fileContent
)
;
}
)
.
then
(
function
(
)
{
return
repo
.
openIndex
(
)
;
}
)
.
then
(
function
(
indexResult
)
{
index
=
indexResult
;
return
index
.
read
(
1
)
;
}
)
.
then
(
function
(
)
{
return
index
.
addByPath
(
fileName
)
;
}
)
.
then
(
function
(
)
{
return
index
.
write
(
)
;
}
)
.
then
(
function
(
)
{
return
index
.
writeTree
(
)
;
}
)
.
then
(
function
(
oidResult
)
{
treeOid
=
oidResult
;
return
NodeGit
.
Reference
.
nameToId
(
repo
,
"HEAD"
)
;
}
)
.
then
(
function
(
head
)
{
return
repo
.
getCommit
(
head
)
;
}
)
.
then
(
function
(
parentResult
)
{
parent
=
parentResult
;
return
Promise
.
all
(
[
NodeGit
.
Signature
.
create
(
"Foo Bar"
,
"foo@bar.com"
,
123456789
,
60
)
,
NodeGit
.
Signature
.
create
(
"Foo A Bar"
,
"foo@bar.com"
,
987654321
,
90
)
]
)
;
}
)
.
then
(
function
(
signatures
)
{
var
author
=
signatures
[
0
]
;
var
committer
=
signatures
[
1
]
;
return
repo
.
createCommit
(
"HEAD"
,
author
,
committer
,
"message"
,
treeOid
,
[
parent
]
)
;
}
)
.
then
(
function
(
commitId
)
{
assert
.
equal
(
expectedCommitId
,
commitId
)
;
}
,
function
(
rejected
)
{
assert
.
fail
(
)
;
}
)
;
}
)
;
describe
(
"author"
,
function
(
)
{
before
(
function
(
)
{
this
.
author
=
this
.
commit
.
author
(
)
;
}
)
;
it
(
"is available"
,
function
(
)
{
assert
.
ok
(
this
.
author
instanceof
NodeGit
.
Signature
)
;
}
)
;
it
(
"has a name"
,
function
(
)
{
assert
.
equal
(
this
.
author
.
name
(
)
,
"Michael Robinson"
)
;
}
)
;
it
(
"has an email"
,
function
(
)
{
assert
.
equal
(
this
.
author
.
email
(
)
,
"mike@panmedia.co.nz"
)
;
}
)
;
}
)
;
describe
(
"committer"
,
function
(
)
{
before
(
function
(
)
{
this
.
author
=
this
.
commit
.
committer
(
)
;
}
)
;
it
(
"is available"
,
function
(
)
{
assert
.
ok
(
this
.
author
instanceof
NodeGit
.
Signature
)
;
}
)
;
it
(
"has a name"
,
function
(
)
{
assert
.
equal
(
this
.
author
.
name
(
)
,
"Michael Robinson"
)
;
}
)
;
it
(
"has an email"
,
function
(
)
{
assert
.
equal
(
this
.
author
.
email
(
)
,
"mike@panmedia.co.nz"
)
;
}
)
;
}
)
;
it
(
"has owner"
,
function
(
)
{
var
owner
=
this
.
commit
.
owner
(
)
;
assert
.
ok
(
owner
instanceof
Repository
)
;
}
)
;
it
(
"can walk its repository's history"
,
function
(
done
)
{
var
historyCount
=
0
;
var
expectedHistoryCount
=
364
;
var
history
=
this
.
commit
.
history
(
)
;
history
.
on
(
"commit"
,
function
(
commit
)
{
historyCount
++
;
}
)
;
history
.
on
(
"end"
,
function
(
commits
)
{
assert
.
equal
(
historyCount
,
expectedHistoryCount
)
;
assert
.
equal
(
commits
.
length
,
expectedHistoryCount
)
;
done
(
)
;
}
)
;
history
.
on
(
"error"
,
function
(
err
)
{
assert
.
ok
(
false
)
;
}
)
;
history
.
start
(
)
;
}
)
;
it
(
"can fetch the master branch HEAD"
,
function
(
)
{
var
repository
=
this
.
repository
;
return
repository
.
getBranchCommit
(
"master"
)
.
then
(
function
(
commit
)
{
return
repository
.
getCommit
(
commit
.
sha
(
)
)
;
}
)
;
}
)
;
it
(
"can fetch all its parents"
,
function
(
)
{
return
this
.
commit
.
getParents
(
)
.
then
(
function
(
parents
)
{
assert
.
equal
(
parents
.
length
,
1
)
;
var
sha
=
parents
[
0
]
.
sha
(
)
;
assert
.
equal
(
sha
,
"ecfd36c80a3e9081f200dfda2391acadb56dac27"
)
;
}
)
;
}
)
;
it
(
"can specify a parents limit"
,
function
(
)
{
return
this
.
commit
.
getParents
(
0
)
.
then
(
function
(
parents
)
{
assert
.
equal
(
parents
.
length
,
0
)
;
}
)
;
}
)
;
it
(
"can specify limit higher than actual parents"
,
function
(
)
{
return
this
.
commit
.
getParents
(
2
)
.
then
(
function
(
parents
)
{
assert
.
equal
(
parents
.
length
,
1
)
;
}
)
;
}
)
;
it
(
"can fetch parents of a merge commit"
,
function
(
)
{
return
NodeGit
.
Repository
.
open
(
reposPath
)
.
then
(
function
(
repo
)
{
return
repo
.
getCommit
(
"bf1da765e357a9b936d6d511f2c7b78e0de53632"
)
;
}
)
.
then
(
function
(
commit
)
{
return
commit
.
getParents
(
)
;
}
)
.
then
(
function
(
parents
)
{
assert
.
equal
(
parents
.
length
,
2
)
;
}
)
;
}
)
;
it
(
"has a parent count"
,
function
(
)
{
assert
.
equal
(
1
,
this
.
commit
.
parentcount
(
)
)
;
}
)
;
it
(
"can retrieve and walk a commit tree"
,
function
(
)
{
var
commitTreeEntryCount
=
0
;
var
expectedCommitTreeEntryCount
=
198
;
return
this
.
commit
.
getTree
(
)
.
then
(
function
(
tree
)
{
return
new
Promise
(
function
(
resolve
,
fail
)
{
var
treeWalker
=
tree
.
walk
(
)
;
treeWalker
.
on
(
"entry"
,
function
(
entry
)
{
commitTreeEntryCount
++
;
}
)
;
treeWalker
.
on
(
"error"
,
function
(
error
)
{
fail
(
error
)
;
}
)
;
treeWalker
.
on
(
"end"
,
function
(
entries
)
{
try
{
assert
.
equal
(
commitTreeEntryCount
,
expectedCommitTreeEntryCount
)
;
resolve
(
)
;
}
catch
(
e
)
{
fail
(
e
)
;
}
}
)
;
treeWalker
.
start
(
)
;
}
)
;
}
)
;
}
)
;
it
(
"can get the commit diff"
,
function
(
)
{
return
this
.
commit
.
getDiff
(
)
.
then
(
function
(
diff
)
{
assert
.
equal
(
diff
.
length
,
1
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL