Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ Reset.default = function(repo, target, pathspecs) {
*/
Reset.reset = function(repo, target, resetType, opts) {
opts = normalizeOptions(opts, NodeGit.CheckoutOptions);

if (repo !== target.repo) {
// this is the same that is performed on libgit2's side
// https://github.com/nodegit/libgit2/blob/8d89e409616831b7b30a5ca7b89354957137b65e/src/reset.c#L120-L124
throw new Error("Repository and target commit's repository does not match");
}
return _reset.call(this, repo, target, resetType, opts);
};

Expand Down
39 changes: 39 additions & 0 deletions test/tests/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,43 @@ describe("Reset", function() {
return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD);
});
});

it("reset fails if parameter is not a Commit object", function() {
var test = this;
var commit = test.repo.getReferenceCommit("master");
try {
Reset.reset(test.repo, commit, Reset.TYPE.HARD);
assert.fail(
"Should not be able to pass a Promise (Commit) into the function"
);
} catch (err) {
// ok
assert.equal(
"Repository and target commit's repository does not match",
err.message
);
}
});

it("reset fails if originating repository is not the same", function() {
var test = this;
var testCommit = null;
return test.repo.getReferenceCommit("master")
.then(function(commit) {
testCommit = commit;
return Repository.open(reposPath);
})
.then(function(repo) {
return Reset.reset(repo, testCommit, Reset.TYPE.HARD);
})
.then(function() {
assert.fail("Different source repository instance should fail");
})
.catch(function(err) {
assert.equal(
"Repository and target commit's repository does not match",
err.message
);
});
});
});