|
1 | | -var nodegit = require("../"); |
2 | | -var path = require("path"); |
3 | | -var fse = require("fs-extra"); |
4 | | -var fileName = "newfile.txt"; |
5 | | -var fileContent = "hello world"; |
6 | | -var directoryName = "salad/toast/strangerinastrangeland/theresnowaythisexists"; |
| 1 | +var nodegit = require('../'); |
| 2 | +var path = require('path'); |
| 3 | +var fse = require('fs-extra'); |
| 4 | +var fileName = 'newfile.txt'; |
| 5 | +var fileContent = 'hello world'; |
| 6 | +var directoryName = 'salad/toast/strangerinastrangeland/theresnowaythisexists'; |
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * This example creates a certain file `newfile.txt`, adds it to the git |
10 | 10 | * index and commits it to head. Similar to a `git add newfile.txt` |
11 | 11 | * followed by a `git commit` |
12 | | -**/ |
| 12 | + **/ |
13 | 13 |
|
14 | 14 | var repo; |
15 | 15 | var index; |
16 | 16 | var oid; |
17 | 17 |
|
18 | | -nodegit.Repository.open(path.resolve(__dirname, "../.git")) |
19 | | -.then(function(repoResult) { |
20 | | - repo = repoResult; |
21 | | - return fse.ensureDir(path.join(repo.workdir(), directoryName)); |
22 | | -}).then(function(){ |
23 | | - return fse.writeFile(path.join(repo.workdir(), fileName), fileContent); |
24 | | -}) |
25 | | -.then(function() { |
26 | | - return fse.writeFile( |
27 | | - path.join(repo.workdir(), directoryName, fileName), |
28 | | - fileContent |
29 | | - ); |
30 | | -}) |
31 | | -.then(function() { |
32 | | - return repo.refreshIndex(); |
33 | | -}) |
34 | | -.then(function(indexResult) { |
35 | | - index = indexResult; |
36 | | -}) |
37 | | -.then(function() { |
38 | | - // this file is in the root of the directory and doesn't need a full path |
39 | | - return index.addByPath(fileName); |
40 | | -}) |
41 | | -.then(function() { |
42 | | - // this file is in a subdirectory and can use a relative path |
43 | | - return index.addByPath(path.posix.join(directoryName, fileName)); |
44 | | -}) |
45 | | -.then(function() { |
46 | | - // this will write both files to the index |
47 | | - return index.write(); |
48 | | -}) |
49 | | -.then(function() { |
50 | | - return index.writeTree(); |
51 | | -}) |
52 | | -.then(function(oidResult) { |
53 | | - oid = oidResult; |
54 | | - return nodegit.Reference.nameToId(repo, "HEAD"); |
55 | | -}) |
56 | | -.then(function(head) { |
57 | | - return repo.getCommit(head); |
58 | | -}) |
59 | | -.then(function(parent) { |
60 | | - var author = nodegit.Signature.now("Scott Chacon", |
61 | | - "schacon@gmail.com"); |
62 | | - var committer = nodegit.Signature.now("Scott A Chacon", |
63 | | - "scott@github.com"); |
| 18 | +nodegit.Repository.open(path.resolve(__dirname, '../.git')) |
| 19 | + .then(function (repoResult) { |
| 20 | + repo = repoResult; |
| 21 | + return fse.ensureDir(path.join(repo.workdir(), directoryName)); |
| 22 | + }) |
| 23 | + .then(function () { |
| 24 | + return fse.writeFile(path.join(repo.workdir(), fileName), fileContent); |
| 25 | + }) |
| 26 | + .then(function () { |
| 27 | + return fse.writeFile(path.join(repo.workdir(), directoryName, fileName), fileContent); |
| 28 | + }) |
| 29 | + .then(function () { |
| 30 | + return repo.refreshIndex(); |
| 31 | + }) |
| 32 | + .then(function (indexResult) { |
| 33 | + index = indexResult; |
| 34 | + }) |
| 35 | + .then(function () { |
| 36 | + // this file is in the root of the directory and doesn't need a full path |
| 37 | + return index.addByPath(fileName); |
| 38 | + }) |
| 39 | + .then(function () { |
| 40 | + // this file is in a subdirectory and can use a relative path |
| 41 | + return index.addByPath(path.posix.join(directoryName, fileName)); |
| 42 | + }) |
| 43 | + .then(function () { |
| 44 | + // this will write both files to the index |
| 45 | + return index.write(); |
| 46 | + }) |
| 47 | + .then(function () { |
| 48 | + return index.writeTree(); |
| 49 | + }) |
| 50 | + .then(function (oidResult) { |
| 51 | + oid = oidResult; |
| 52 | + return nodegit.Reference.nameToId(repo, 'HEAD'); |
| 53 | + }) |
| 54 | + .then(function (head) { |
| 55 | + return repo.getCommit(head); |
| 56 | + }) |
| 57 | + .then(function (parent) { |
| 58 | + var author = nodegit.Signature.now('Scott Chacon', 'schacon@gmail.com'); |
| 59 | + var committer = nodegit.Signature.now('Scott A Chacon', 'scott@github.com'); |
64 | 60 |
|
65 | | - return repo.createCommit("HEAD", author, committer, "message", oid, [parent]); |
66 | | -}) |
67 | | -.done(function(commitId) { |
68 | | - console.log("New Commit: ", commitId); |
69 | | -}); |
| 61 | + return repo.createCommit('HEAD', author, committer, 'message', oid, [parent]); |
| 62 | + }) |
| 63 | + .done(function (commitId) { |
| 64 | + console.log('New Commit: ', commitId); |
| 65 | + }); |
0 commit comments