Skip to content

Commit baee388

Browse files
committed
Bug fixes
1 parent 1f86238 commit baee388

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

include/reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GitReference : public ObjectWrap {
4646
const char * name;
4747
Persistent<Function> callback;
4848
};
49-
static Handle<Value> Oid(const Arguments& args);
49+
static Handle<Value> Target(const Arguments& args);
5050
static Handle<Value> SymbolicTarget(const Arguments& args);
5151
static Handle<Value> Type(const Arguments& args);
5252
static Handle<Value> Name(const Arguments& args);

lib/reference.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,42 @@ Reference.Type = {
77
All: 3
88
};
99

10-
Reference.prototype.isOid = function() {
10+
/**
11+
* Returns true if this reference is not symbolic
12+
*/
13+
Reference.prototype.isConcrete = function() {
1114
return this.type() == Reference.Type.Oid;
1215
};
1316

17+
/**
18+
* Returns true if this reference is symbolic
19+
*/
1420
Reference.prototype.isSymbolic = function() {
1521
return this.type() == Reference.Type.Symbolic;
1622
};
1723

24+
/**
25+
* Returns the target of this symbolic reference.
26+
* @throws if the target is not symbolic.
27+
*/
1828
var oldSymbolicTarget = Reference.prototype.symbolicTarget;
1929
Reference.prototype.symbolicTarget = function() {
2030
if (!this.isSymbolic()) throw this.name() + " is not symbolic";
2131

2232
return oldSymbolicTarget.call(this);
2333
};
2434

25-
var oldOid = Reference.prototype.oid;
26-
Reference.prototype.oid = function() {
27-
if (!this.isOid()) throw this.name() + " is not oid";
35+
/**
36+
* Returns the oid of this non-symbolic reference.
37+
* @throws if the target is symbolic.
38+
*/
39+
var oldTarget = Reference.prototype.target;
40+
Reference.prototype.target = function() {
41+
if (!this.isConcrete()) throw this.name() + " is symbolic";
2842

29-
return oldOid.call(this);
43+
return oldTarget.call(this);
3044
};
45+
46+
Reference.prototype.toString = function() {
47+
return this.name();
48+
}

lib/repo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Repo.prototype.getBranch = function(name, callback) {
2020
this.getReference('refs/heads/' + name, function referenceLookupCallback(error, reference) {
2121
if (error) return callback(error);
2222

23-
self.getCommit(reference.oid(), function commitLookupCallback(error, commit) {
23+
self.getCommit(reference.target(), function commitLookupCallback(error, commit) {
2424
if (error) return callback(error);
2525

2626
callback(null, commit);

lib/tree.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ Tree.prototype.getEntry = function(path, callback) {
4747
oldGetEntry.call(this, path, function(error, entry) {
4848
if (error) return callback(error);
4949

50-
// This is unlikely to be the *direct* parent; some methods, like `path()`
51-
// rely on directness.
5250
entry.parent = self;
51+
entry.path = function() { return path };
5352
callback(null, entry);
5453
});
5554
};

lib/tree_builder.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ TreeBuilder.prototype.write = function(callback) {
4343
this.doInsertions(function(error) {
4444
if (error) return callback(error);
4545

46-
if (self.builders.length) writeNextLevel(self.repo, self.builders, function(error, previousName, previousTreeId) {
47-
if (previousName && previousTreeId) {
48-
oldInsert.call(self, previousName, previousTreeId, TreeEntry.FileMode.Tree);
49-
}
46+
if (self.builders && self.builders.length) {
47+
writeNextLevel(self.repo, self.builders, function(error, previousName, previousTreeId) {
48+
if (previousName && previousTreeId) {
49+
oldInsert.call(self, previousName, previousTreeId, TreeEntry.FileMode.Tree);
50+
}
51+
oldWrite.call(self, self.repo, callback);
52+
});
53+
} else {
5054
oldWrite.call(self, self.repo, callback);
51-
});
55+
}
5256
})
5357
};
5458

lib/tree_entry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ TreeEntry.prototype.isTree = function() {
2727
};
2828

2929
TreeEntry.prototype.isDirectory = TreeEntry.prototype.isTree;
30+
TreeEntry.prototype.isBlob = TreeEntry.prototype.isFile;
3031

3132
/**
3233
* Retrieve the SHA for this TreeEntry.
@@ -63,5 +64,5 @@ TreeEntry.prototype.path = function(callback) {
6364
};
6465

6566
TreeEntry.prototype.toString = function() {
66-
return this.name();
67+
return this.path();
6768
};

src/reference.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void GitReference::Initialize(Handle<v8::Object> target) {
3434
tpl->SetClassName(String::NewSymbol("Reference"));
3535

3636
NODE_SET_METHOD(tpl, "oidForName", OidForName);
37-
NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid);
37+
NODE_SET_PROTOTYPE_METHOD(tpl, "target", Target);
3838
NODE_SET_PROTOTYPE_METHOD(tpl, "symbolicTarget", SymbolicTarget);
3939
NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type);
4040
NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name);
@@ -169,7 +169,7 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) {
169169
/**
170170
* @return {GitOid} result
171171
*/
172-
Handle<Value> GitReference::Oid(const Arguments& args) {
172+
Handle<Value> GitReference::Target(const Arguments& args) {
173173
HandleScope scope;
174174

175175

v0.18.0.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7944,8 +7944,8 @@
79447944
"isAsync": false,
79457945
"isConstructorMethod": false,
79467946
"isPrototypeMethod": true,
7947-
"jsFunctionName": "oid",
7948-
"cppFunctionName": "Oid",
7947+
"jsFunctionName": "target",
7948+
"cppFunctionName": "Target",
79497949
"return": {
79507950
"cType": "const git_oid *",
79517951
"cppClassName": "GitOid",

0 commit comments

Comments
 (0)