Skip to content

Commit dd5acb9

Browse files
author
John Haley
committed
Renamed getBranch and getMaster to more a more accurate name
1 parent d0f834f commit dd5acb9

8 files changed

Lines changed: 53 additions & 47 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ var open = require("nodegit").Repository.open;
134134
open("tmp")
135135
// Open the master branch.
136136
.then(function(repo) {
137-
return repo.getMaster();
137+
return repo.getMasterCommit();
138138
})
139139
// Display information about commits on master.
140-
.then(function(branch) {
140+
.then(function(firstCommitOnMaster) {
141141
// Create a new history event emitter.
142-
var history = branch.history();
142+
var history = firstCommitOnMaster.history();
143143

144144
// Create a counter to only show up to 9 entries.
145145
var count = 0;

example/apps/git_profanity_check.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,25 @@ else {
3535
}
3636

3737
// Open repository.
38-
git.Repo.open(path, function(err, repo) {
39-
if (err) {
40-
throw new Error(err);
41-
}
42-
38+
git.Repo.open(path)
39+
.then(function(repo) {
4340
// Open branch, default to master.
44-
repo.getBranch(branch, function(err, branch) {
45-
if (err) {
46-
throw new Error(err);
41+
return repo.getBranchCommit(branch);
42+
}).then(function(firstCommit) {
43+
// Iterate history
44+
var history = firstCommit.history();
45+
46+
// Iterate over every commit message and test for words.
47+
history.on('commit', function(commit) {
48+
var message = commit.message();
49+
50+
if (reCurse.test(message)) {
51+
console.log('Curse detected in commit', commit.sha());
52+
console.log('=> ', message);
53+
return;
4754
}
48-
49-
// Iterate history
50-
var history = branch.history();
51-
52-
// Iterate over every commit message and test for words.
53-
history.on('commit', function(commit) {
54-
var message = commit.message();
55-
56-
if (reCurse.test(message)) {
57-
console.log('Curse detected in commit', commit.sha());
58-
console.log('=> ', message);
59-
return;
60-
}
61-
});
62-
63-
// Start history iteration.
64-
history.start();
6555
});
56+
57+
// Start history iteration.
58+
history.start();
6659
});

example/walk-history.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ var nodegit = require('../'),
66
// that look very similar to calling `git log` from the command line
77

88
nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) {
9-
return repo.getMaster();
10-
}).then(function(branch){
9+
return repo.getMasterCommit();
10+
}).then(function(firstCommitOnMaster){
1111
// History returns an event.
12-
var history = branch.history(sort.Time);
12+
var history = firstCommitOnMaster.history(sort.Time);
1313

1414
// History emits 'commit' event for each commit in the branch's history
1515
history.on('commit', function(commit) {

example/walk-tree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ var nodegit = require('../'),
66
// tree (directory), or a file.
77

88
nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) {
9-
return repo.getMaster();
10-
}).then(function(branch) {
11-
return branch.getTree();
9+
return repo.getMasterCommit();
10+
}).then(function(firstCommitOnMaster) {
11+
return firstCommitOnMaster.getTree();
1212
}).then(function(tree) {
1313
// `walk()` returns an event.
1414
var walker = tree.walk();

generate/descriptor.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@
8787
"functions": {
8888
"git_branch_next": {
8989
"ignore": true
90+
},
91+
"git_branch_create": {
92+
"args": {
93+
"force": {
94+
"isOptional": true
95+
},
96+
"signature": {
97+
"isOptional": true
98+
},
99+
"log_message": {
100+
"isOptional": true
101+
}
102+
}
90103
}
91104
}
92105
},

lib/repository.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Object.defineProperty(Repository.prototype, "openIndex", {
2424
* @param {Function} callback
2525
* @return {Branch}
2626
*/
27-
Repository.prototype.getBranch = function(name, callback) {
27+
Repository.prototype.getBranchCommit = function(name, callback) {
2828
var repository = this;
2929

3030
return this.getReference("refs/heads/" + name).then(function(reference) {
@@ -262,13 +262,13 @@ Repository.prototype.createRevWalk = function() {
262262
};
263263

264264
/**
265-
* Retrieve the master branch.
265+
* Retrieve the master branch commit.
266266
*
267267
* @param {Function} callback
268268
* @return {Branch}
269269
*/
270-
Repository.prototype.getMaster = function(callback) {
271-
return this.getBranch("master", callback);
270+
Repository.prototype.getMasterCommit = function(callback) {
271+
return this.getBranchCommit("master", callback);
272272
};
273273

274274
/**

test/tests/commit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ describe("Commit", function() {
177177
it("can fetch the master branch HEAD", function() {
178178
var repository = this.repository;
179179

180-
return repository.getBranch("master").then(function(branch) {
181-
return repository.getCommit(branch.sha());
180+
return repository.getBranchCommit("master").then(function(commit) {
181+
return repository.getCommit(commit.sha());
182182
});
183183
});
184184

test/tests/revwalk.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ describe("Revwalk", function() {
1212
var test = this;
1313
return Repository.open(reposPath).then(function(repository) {
1414
test.repository = repository;
15-
return test.repository.getBranch("rev-walk").then(function(branch) {
16-
test.branch = branch;
15+
return test.repository.getBranchCommit("rev-walk").then(function(commit) {
16+
test.commit = commit;
1717
done();
1818
});
1919
});
2020
});
2121

2222
beforeEach(function() {
2323
this.walker = this.repository.createRevWalk();
24-
this.walker.push(this.branch.id());
24+
this.walker.push(this.commit.id());
2525
});
2626

2727
it("can create a walker", function() {
2828
assert.ok(this.walker instanceof Revwalk);
2929
});
3030

3131
it("can push an object", function() {
32-
var sha = this.branch.sha();
32+
var sha = this.commit.sha();
3333

3434
return this.walker.next().then(function(commit) {
3535
assert.equal(sha, commit);
@@ -49,7 +49,7 @@ describe("Revwalk", function() {
4949
assert.equal(commit.toString(),
5050
"b8a94aefb22d0534cc0e5acf533989c13d8725dc");
5151
test.walker = test.repository.createRevWalk();
52-
test.walker.push(test.branch.id());
52+
test.walker.push(test.commit.id());
5353
test.walker.hide(
5454
Oid.fromString("b8a94aefb22d0534cc0e5acf533989c13d8725dc"));
5555

@@ -89,9 +89,9 @@ describe("Revwalk", function() {
8989
this.timeout(10000);
9090
return Repository.open(reposPath).then(function(repository) {
9191
var walker = repository.createRevWalk();
92-
return repository.getMaster().then(function(master) {
92+
return repository.getMasterCommit().then(function(firstCommitOnMaster) {
9393
var did = false;
94-
walker.walk(master, function(error, commit) {
94+
walker.walk(firstCommitOnMaster, function(error, commit) {
9595
for (var i = 0; i < 1000; i++) {
9696
if (true) {
9797
commit.author().name();

0 commit comments

Comments
 (0)