Skip to content

Commit 25ae260

Browse files
committed
bug fixes
1 parent faefa7c commit 25ae260

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

example/general.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
308308
// references such as branches, tags and remote references (everything in
309309
// the .git/refs directory).
310310

311-
repo.getReferences(git.Reference.Type.Oid | git.Reference.Type.Symbolic, function(error, referenceNames) {
311+
repo.getReferences(git.Reference.Type.All, function(error, referenceNames) {
312312
if (error) throw error;
313313

314314
referenceNames.forEach(function(referenceName) {

include/reference.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class GitReference : public ObjectWrap {
4747
Persistent<Function> callback;
4848
};
4949
static Handle<Value> Oid(const Arguments& args);
50-
static Handle<Value> Name(const Arguments& args);
50+
static Handle<Value> SymbolicTarget(const Arguments& args);
5151
static Handle<Value> Type(const Arguments& args);
52+
static Handle<Value> Name(const Arguments& args);
5253
static Handle<Value> Resolve(const Arguments& args);
5354
static void ResolveWork(uv_work_t* req);
5455
static void ResolveAfterWork(uv_work_t* req);

lib/reference.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var git = require('../'),
33

44
Reference.Type = {
55
Oid: 1,
6-
Symbolic: 2
6+
Symbolic: 2,
7+
All: 3
78
};
89

910
Reference.prototype.isOid = function() {
@@ -13,3 +14,17 @@ Reference.prototype.isOid = function() {
1314
Reference.prototype.isSymbolic = function() {
1415
return this.type() == Reference.Type.Symbolic;
1516
};
17+
18+
var oldSymbolicTarget = Reference.prototype.symbolicTarget;
19+
Reference.prototype.symbolicTarget = function() {
20+
if (!this.isSymbolic()) throw this.name() + " is not symbolic";
21+
22+
return oldSymbolicTarget.call(this);
23+
};
24+
25+
var oldOid = Reference.prototype.oid;
26+
Reference.prototype.oid = function() {
27+
if (!this.isOid()) throw this.name() + " is not oid";
28+
29+
return oldOid.call(this);
30+
};

src/reference.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ void GitReference::Initialize(Handle<v8::Object> target) {
3535

3636
NODE_SET_METHOD(tpl, "oidForName", OidForName);
3737
NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid);
38-
NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name);
38+
NODE_SET_PROTOTYPE_METHOD(tpl, "symbolicTarget", SymbolicTarget);
3939
NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type);
40+
NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name);
4041
NODE_SET_PROTOTYPE_METHOD(tpl, "resolve", Resolve);
4142
NODE_SET_PROTOTYPE_METHOD(tpl, "setSymbolicTarget", SetSymbolicTarget);
4243
NODE_SET_PROTOTYPE_METHOD(tpl, "setTarget", setTarget);
@@ -179,7 +180,7 @@ Handle<Value> GitReference::Oid(const Arguments& args) {
179180
/**
180181
* @return {String} result
181182
*/
182-
Handle<Value> GitReference::Name(const Arguments& args) {
183+
Handle<Value> GitReference::SymbolicTarget(const Arguments& args) {
183184
HandleScope scope;
184185

185186

@@ -208,6 +209,22 @@ Handle<Value> GitReference::Type(const Arguments& args) {
208209
return scope.Close(to);
209210
}
210211

212+
/**
213+
* @return {String} result
214+
*/
215+
Handle<Value> GitReference::Name(const Arguments& args) {
216+
HandleScope scope;
217+
218+
219+
const char * result = git_reference_name(
220+
ObjectWrap::Unwrap<GitReference>(args.This())->GetValue()
221+
);
222+
223+
Handle<Value> to;
224+
to = String::New(result);
225+
return scope.Close(to);
226+
}
227+
211228
/**
212229
* @param {Reference} callback
213230
*/

test/repo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ exports.open = function(test){
1111
test.expect(2);
1212

1313
// Test invalid repository
14-
git.Repo.open('/private/etc/hosts', function(error, repository) {
15-
test.equals(error.message, "The `.git` file at '/private/etc/hosts' is malformed");
14+
git.Repo.open('../templates', function(error, repository) {
15+
test.equals(error.message, "Could not find repository from '../templates'");
1616

1717
// Test valid repository
1818
git.Repo.open('../.git', function(error, repository) {

v0.18.0.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8123,8 +8123,8 @@
81238123
"isAsync": false,
81248124
"isConstructorMethod": false,
81258125
"isPrototypeMethod": true,
8126-
"jsFunctionName": "name",
8127-
"cppFunctionName": "Name",
8126+
"jsFunctionName": "symbolicTarget",
8127+
"cppFunctionName": "SymbolicTarget",
81288128
"return": {
81298129
"cType": "const char *",
81308130
"cppClassName": "String"
@@ -8162,7 +8162,6 @@
81628162
"isSelf": true
81638163
}
81648164
],
8165-
"ignore": true,
81668165
"isAsync": false,
81678166
"isConstructorMethod": false,
81688167
"isPrototypeMethod": true,

0 commit comments

Comments
 (0)