FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/examples/remove-and-commit.js at v0.26.0 · 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
/
examples
/
remove-and-commit.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (52 loc) · 1.44 KB
Breadcrumbs
nodegit
/
examples
/
remove-and-commit.js
Copy path
File metadata and controls
56 lines (52 loc) · 1.44 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
var
nodegit
=
require
(
"../"
)
,
path
=
require
(
"path"
)
,
fileName
=
"newfile.txt"
;
/**
* This example deletes a certain file `newfile.txt`,
* removes it from the git index and commits it to head. Similar to a
* `git rm newfile.txt` followed by a `git commit`. Use add-and-commit.js
* to create the file first.
**/
var
_repository
;
var
_index
;
var
_oid
;
//open a git repo
nodegit
.
Repository
.
open
(
path
.
resolve
(
__dirname
,
"../.git"
)
)
.
then
(
function
(
repo
)
{
_repository
=
repo
;
return
repo
.
refreshIndex
(
)
;
}
)
.
then
(
function
(
index
)
{
_index
=
index
;
}
)
.
then
(
function
(
)
{
//remove the file from the index...
return
_index
.
removeByPath
(
fileName
)
;
}
)
.
then
(
function
(
)
{
return
_index
.
write
(
)
;
}
)
.
then
(
function
(
)
{
return
_index
.
writeTree
(
)
;
}
)
.
then
(
function
(
oid
)
{
_oid
=
oid
;
return
nodegit
.
Reference
.
nameToId
(
_repository
,
"HEAD"
)
;
}
)
.
then
(
function
(
head
)
{
return
_repository
.
getCommit
(
head
)
;
}
)
.
then
(
function
(
parent
)
{
var
author
=
nodegit
.
Signature
.
now
(
"Scott Chacon"
,
"schacon@gmail.com"
)
;
var
committer
=
nodegit
.
Signature
.
now
(
"Scott A Chacon"
,
"scott@github.com"
)
;
return
_repository
.
createCommit
(
"HEAD"
,
author
,
committer
,
"message"
,
_oid
,
[
parent
]
)
;
}
)
.
then
(
function
(
commitId
)
{
// the file is removed from the git repo, use fs.unlink now to remove it
// from the filesystem.
console
.
log
(
"New Commit:"
,
commitId
.
allocfmt
(
)
)
;
}
)
.
done
(
)
;
Back
|
FazBrowse Home
|
New Git URL