Skip to content

Commit 572ae33

Browse files
committed
Status example
1 parent 01fbc0c commit 572ae33

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/status.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var nodegit = require("../"),
2+
path = require("path");
3+
4+
// This code shows working directory changes similar to git status
5+
6+
nodegit.Repository.open(path.resolve(__dirname, "../.git"))
7+
.then(function(repo) {
8+
repo.getStatus().then(function(statuses) {
9+
function statusToText(status) {
10+
var words = [];
11+
if (status.isNew()) { words.push("NEW"); }
12+
if (status.isModified()) { words.push("MODIFIED"); }
13+
if (status.isTypechange()) { words.push("TYPECHANGE"); }
14+
if (status.isRenamed()) { words.push("RENAMED"); }
15+
if (status.isIgnored()) { words.push("IGNORED"); }
16+
17+
return words.join(" ");
18+
}
19+
20+
statuses.forEach(function(file) {
21+
console.log(file.path() + " " + statusToText(file));
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)