FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cherrypick tests by jdgarcia · Pull Request #595 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
options wrapper and test for Cherrypick.commit
  • Loading branch information
jdgarcia committed Jun 1, 2015
commit a8b8303ad19ca16d2467ed2243ad8e86b1193891
32 changes: 31 additions & 1 deletion lib/cherrypick.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var normalizeOptions = NodeGit.Utils.normalizeOptions;

var Cherrypick = NodeGit.Cherrypick;
var _cherrypick = Cherrypick.cherrypick;
var _commit = Cherrypick.commit;

/**
* Cherrypick a commit and, changing the index and working directory
*
* @async
* @param {Repository} repo The repo to checkout head
* @param {Commit} commit The commit to cherrypick
* @param {CherrypickOptions} [options] Options for the cherrypick
Expand Down Expand Up @@ -40,3 +40,33 @@ Cherrypick.cherrypick = function(repo, commit, options) {

return _cherrypick.call(this, repo, commit, options);
};

/**
* Cherrypicks the given commit against "our" commit, producing an index that
* reflects the result of the cherrypick. The index is not backed by a repo.
*
* @async
* @param {Repository} repo The repo to cherrypick commits
* @param {Commit} cherrypick_commit The commit to cherrypick
* @param {Commit} our_commit The commit to revert against
* @param {int} mainline The parent of the revert commit (1 or
* 2) if it's a merge, 0 otherwise
* @param {MergeOptions} [merge_options] Merge options for the cherrypick
* @return {int} 0 on success, -1 on failure
*/
Cherrypick.commit = function(
repo,
cherrypick_commit,
our_commit,
mainline,
merge_options) {
merge_options = normalizeOptions(merge_options, NodeGit.MergeOptions);

return _commit.call(
this,
repo,
cherrypick_commit,
our_commit,
mainline,
merge_options);
};
40 changes: 40 additions & 0 deletions test/tests/cherrypick.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,44 @@ describe("Cherrypick", function() {
repoInfo.theirFileName + " should exist");
});
});

it("can cherrypick a commit onto another specified commit", function() {
var repo = this.repository;
var workDirPath = repo.workdir();
var repoInfo;

return setupBranches(repo)
.then(function(info) {
repoInfo = info;

assert(!fse.existsSync(path.join(workDirPath, repoInfo.ourFileName)),
repoInfo.ourFileName + " shouldn't exist");
assert(!fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " shouldn't exist");

return Cherrypick.commit(repo, repoInfo.theirCommit, repoInfo.ourCommit, 0, {});
})
.then(function(index) {
assert(index);
index.write();

return index.writeTreeTo(repo);
})
.then(function(oid) {
return repo.getTree(oid);
})
.then(function(tree) {
var opts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE
};

return NodeGit.Checkout.tree(repo, tree, opts);
})
.then(function() {
assert(fse.existsSync(path.join(workDirPath, repoInfo.ourFileName)),
repoInfo.ourFileName + " should exist");
assert(fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " should exist");
});
});
});

Back | FazBrowse Home | New Git URL