-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnew-commit.js
More file actions
executable file
·32 lines (24 loc) · 1.08 KB
/
new-commit.js
File metadata and controls
executable file
·32 lines (24 loc) · 1.08 KB
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
var git = require('../'),
path = require('path');
// This example opens a certain file, `README.md`, at a particular commit,
// and prints the first 10 lines as well as some metadata.
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
if (error) throw error;
repo.getCommit('eebd0ead15d62eaf0ba276da53af43bbc3ce43ab', function(error, commit) {
if (error) throw error;
commit.getTree(function(error, tree) {
if (error) throw error;
var builder = tree.builder(),
buffer = new Buffer("this is a file\n");
builder.insertBlob("/lib/baz.txt", buffer, false)
builder.write(function(error, treeId) {
if (error) throw error;
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);
repo.createCommit(null, author, committer, "message", treeId, [commit], function(error, commitId) {
console.log("New Commit:", commitId.sha());
});
});
});
});
});