FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/example/remove-and-commit.js at master · ashwinraghav/nodegit · GitHub
ashwinraghav
nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
example
/
remove-and-commit.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (43 loc) · 1.82 KB
Breadcrumbs
nodegit
/
example
/
remove-and-commit.js
Copy path
File metadata and controls
53 lines (43 loc) · 1.82 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
var
git
=
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.
**/
//open a git repo
git
.
Repo
.
open
(
path
.
resolve
(
__dirname
,
'../.git'
)
,
function
(
openReporError
,
repo
)
{
if
(
openReporError
)
throw
openReporError
;
//remove the file from the index...
repo
.
openIndex
(
function
(
openIndexError
,
index
)
{
if
(
openIndexError
)
throw
openIndexError
;
index
.
read
(
function
(
readError
)
{
if
(
readError
)
throw
readError
;
index
.
removeByPath
(
fileName
)
;
index
.
write
(
function
(
writeError
)
{
if
(
writeError
)
throw
writeError
;
index
.
writeTree
(
function
(
writeTreeError
,
oid
)
{
if
(
writeTreeError
)
throw
writeTreeError
;
//get HEAD
git
.
Reference
.
oidForName
(
repo
,
'HEAD'
,
function
(
oidForName
,
head
)
{
if
(
oidForName
)
throw
oidForName
;
//get latest commit (will be the parent commit)
repo
.
getCommit
(
head
,
function
(
getCommitError
,
parent
)
{
if
(
getCommitError
)
throw
getCommitError
;
var
author
=
git
.
Signature
.
create
(
"Scott Chacon"
,
"schacon@gmail.com"
,
123456789
,
60
)
;
var
committer
=
git
.
Signature
.
create
(
"Scott A Chacon"
,
"scott@github.com"
,
987654321
,
90
)
;
//commit
repo
.
createCommit
(
'HEAD'
,
author
,
committer
,
'message'
,
oid
,
[
parent
]
,
function
(
error
,
commitId
)
{
console
.
log
(
"New Commit:"
,
commitId
.
sha
(
)
)
;
// the file is removed from the git repo, use fs.unlink now to remove it
// from the filesystem.
}
)
;
}
)
;
}
)
;
}
)
;
}
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL