Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2be19e8

Browse files
author
Ændrew Rininsland
committed
Merge pull request github-tools#202 from ctalau/master
Fixed commit on and read from a non-master branch
2 parents f2087b2 + 4daae44 commit 2be19e8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

github.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390

391391
this.getSha = function(branch, path, cb) {
392392
if (!path || path === "") return that.getRef("heads/"+branch, cb);
393-
_request("GET", repoPath + "/contents/"+path, {ref: branch}, function(err, pathContent) {
393+
_request("GET", repoPath + "/contents/" + path + (branch ? "?ref=" + branch : ""), null, function(err, pathContent) {
394394
if (err) return cb(err);
395395
cb(null, pathContent.sha);
396396
});
@@ -603,7 +603,7 @@
603603
// -------
604604

605605
this.read = function(branch, path, cb) {
606-
_request("GET", repoPath + "/contents/"+encodeURI(path), {ref: branch}, function(err, obj) {
606+
_request("GET", repoPath + "/contents/"+encodeURI(path) + (branch ? "?ref=" + branch : ""), null, function(err, obj) {
607607
if (err && err.error === 404) return cb("not found", null, null);
608608

609609
if (err) return cb(err);

test/test.repo.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ test('Create Repo', function(t) {
112112
});
113113
});
114114

115+
t.test('repo.writeBranch', function(q) {
116+
repo.branch('master', 'dev', function(err) {
117+
q.error(err);
118+
repo.write('dev', 'TEST.md', 'THIS IS AN UPDATED TEST', 'Updating test', function(err) {
119+
q.error(err);
120+
repo.read('dev', 'TEST.md', function(err, obj) {
121+
t.equals('THIS IS AN UPDATED TEST', obj);
122+
q.error(err);
123+
q.end();
124+
});
125+
});
126+
});
127+
});
128+
115129
t.test('repo.writeChinese', function(q) {
116130
repo.write('master', '中文测试.md', 'THIS IS A TEST', 'Creating test', function(err) {
117131
q.error(err);

0 commit comments

Comments
 (0)