-
Notifications
You must be signed in to change notification settings - Fork 56
/
display-commit-tree.js
40 lines (32 loc) · 1.09 KB
/
display-commit-tree.js
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
/**
* This example will load the Git repository for gitteh, and display the commit
* tree of the latest revision. You have to have cloned the gitteh Git repo for
* this to work, of course.
*/
var gitteh = require("gitteh"),
path = require("path"),
fs = require("fs");
var repository = gitteh.openRepository(path.join(__dirname, "..", ".git"));
var headRef = repository.getReference("HEAD");
headRef = headRef.resolve();
var commit = repository.getCommit(headRef.target);
var displayTreeContents = function(treeId, tabs) {
var tree = repository.getTree(treeId);
var tabStr = ""; for(var i = 0; i < tabs; i++) tabStr += " ";
for(var i = 0, len = tree.entries.length; i < len; i++) {
var entry = tree.entries[i];
var line = tabStr ;
line += entry.name;
// 16384 == 40000 in octal (which is directory attribute in Git).
if(entry.attributes == 16384) {
line += "/";
console.log(line);
displayTreeContents(entry.id, tabs + 1);
}
else {
//line += " - " + entry.id;
console.log(line);
}
}
};
displayTreeContents(commit.tree, 1);