Skip to content

Commit f645360

Browse files
committed
Merge pull request nodegit#990 from nodegit/async-remote-create
Make `Remote.create` async
2 parents 786add2 + 2e0e6de commit f645360

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

generate/input/descriptor.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,10 @@
16301630
"selfFreeing": true,
16311631
"functions": {
16321632
"git_remote_create": {
1633-
"isAsync": false
1633+
"isAsync": true,
1634+
"return": {
1635+
"isErrorCode": true
1636+
}
16341637
},
16351638
"git_remote_connect": {
16361639
"isAsync": true,

test/tests/remote.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ describe("Remote", function() {
6363

6464
it("can set a remote", function() {
6565
var repository = this.repository;
66-
Remote.create(repository, "origin1", url);
6766

68-
Remote.setPushurl(repository, "origin1", "https://google.com/");
69-
70-
return Remote.lookup(repository, "origin1").then(function(remote) {
71-
assert.equal(remote.pushurl(), "https://google.com/");
72-
});
67+
return Remote.create(repository, "origin1", url)
68+
.then(function() {
69+
return Remote.setPushurl(repository, "origin1", "https://google.com/");
70+
})
71+
.then(function() {
72+
return Remote.lookup(repository, "origin1");
73+
})
74+
.then(function(remote) {
75+
assert.equal(remote.pushurl(), "https://google.com/");
76+
});
7377
});
7478

7579
it("can read the remote name", function() {
@@ -78,22 +82,28 @@ describe("Remote", function() {
7882

7983
it("can create and load a new remote", function() {
8084
var repository = this.repository;
81-
Remote.create(repository, "origin2", url);
8285

83-
return Remote.lookup(repository, "origin2").then(function(remote) {
84-
assert(remote.url(), url);
85-
});
86+
return Remote.create(repository, "origin2", url)
87+
.then(function() {
88+
return Remote.lookup(repository, "origin2");
89+
})
90+
.then(function(remote) {
91+
assert(remote.url(), url);
92+
});
8693
});
8794

8895
it("can delete a remote", function() {
8996
var repository = this.repository;
90-
Remote.create(repository, "origin3", url);
9197

92-
return Remote.delete(repository, "origin3")
98+
return Remote.create(repository, "origin3", url)
9399
.then(function() {
94-
return Remote.lookup(repository, "origin3");
100+
return Remote.delete(repository, "origin3");
95101
})
96-
.then(Promise.reject.bind(Promise), Promise.resolve.bind(Promise));
102+
.then(function() {
103+
return Remote.lookup(repository, "origin3")
104+
// We only want to catch the failed lookup
105+
.then(Promise.reject.bind(Promise), Promise.resolve.bind(Promise));
106+
});
97107
});
98108

99109
it("can download from a remote", function() {
@@ -124,9 +134,7 @@ describe("Remote", function() {
124134
var repo = this.repository;
125135
var wasCalled = false;
126136

127-
Remote.create(repo, "test2", url2);
128-
129-
return repo.getRemote("test2")
137+
return Remote.create(repo, "test2", url2)
130138
.then(function(remote) {
131139
var fetchOpts = {
132140
callbacks: {
@@ -183,7 +191,6 @@ describe("Remote", function() {
183191

184192
it("can fetch from a private repository", function() {
185193
var repo = this.repository;
186-
var remote = Remote.create(repo, "private", privateUrl);
187194
var fetchOptions = {
188195
callbacks: {
189196
credentials: function(url, userName) {
@@ -200,7 +207,10 @@ describe("Remote", function() {
200207
}
201208
};
202209

203-
return remote.fetch(null, fetchOptions, "Fetch from private")
210+
return Remote.create(repo, "private", privateUrl)
211+
.then(function(remote) {
212+
return remote.fetch(null, fetchOptions, "Fetch from private");
213+
})
204214
.catch(function() {
205215
assert.fail("Unable to fetch from private repository");
206216
});
@@ -209,7 +219,6 @@ describe("Remote", function() {
209219
it("can reject fetching from private repository without valid credentials",
210220
function() {
211221
var repo = this.repository;
212-
var remote = Remote.create(repo, "private", privateUrl);
213222
var firstPass = true;
214223
var fetchOptions = {
215224
callbacks: {
@@ -225,7 +234,10 @@ describe("Remote", function() {
225234
}
226235
};
227236

228-
return remote.fetch(null, fetchOptions, "Fetch from private")
237+
return Remote.create(repo, "private", privateUrl)
238+
.then(function(remote) {
239+
return remote.fetch(null, fetchOptions, "Fetch from private");
240+
})
229241
.then(function () {
230242
assert.fail("Should not be able to fetch from repository");
231243
})
@@ -240,19 +252,23 @@ describe("Remote", function() {
240252

241253
it("can fetch from all remotes", function() {
242254
var repository = this.repository;
243-
Remote.create(repository, "test1", url);
244-
Remote.create(repository, "test2", url2);
245255

246-
return repository.fetchAll({
247-
callbacks: {
248-
credentials: function(url, userName) {
249-
return NodeGit.Cred.sshKeyFromAgent(userName);
250-
},
251-
certificateCheck: function() {
252-
return 1;
253-
}
254-
}
255-
});
256+
return Remote.create(repository, "test1", url)
257+
.then(function() {
258+
return Remote.create(repository, "test2", url2);
259+
})
260+
.then(function() {
261+
return repository.fetchAll({
262+
callbacks: {
263+
credentials: function(url, userName) {
264+
return NodeGit.Cred.sshKeyFromAgent(userName);
265+
},
266+
certificateCheck: function() {
267+
return 1;
268+
}
269+
}
270+
});
271+
});
256272
});
257273

258274
it("will reject if credentials promise rejects", function() {

0 commit comments

Comments
 (0)