From d6ed167156b0be54001ea6227c9def5e6a2d5e12 Mon Sep 17 00:00:00 2001 From: Louis De Bevere Date: Wed, 9 Mar 2016 11:53:54 +0100 Subject: [PATCH 1/3] Pass options to git checkout --- src/repo.coffee | 9 +++++++-- test/repo.test.coffee | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/repo.coffee b/src/repo.coffee index 3c0e2be..7aa0fc4 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -365,8 +365,13 @@ module.exports = class Repo # Public: Checkout the treeish. - checkout: (treeish, callback) -> - @git "checkout", {}, treeish, callback + # + # options - The {Object} containing any of the options available to git checkout: + # :b - {Boolean) Creates a branch when it doesn't exist yet. + # + checkout: (treeish, options, callback) -> + [options, callback] = [{}, options] if !callback + @git "checkout", options, treeish, callback # Public: Clean the git repo by removing untracked files # diff --git a/test/repo.test.coffee b/test/repo.test.coffee index a0ce37b..69014f0 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -676,6 +676,37 @@ describe "Repo", -> status.files.should.not.have.a.property file status.files.should.not.have.a.property 'rawr.txt' + describe "#checkout", -> + repo = null + head = null + git_dir = __dirname + "/fixtures/junk_checkout" + + # given a fresh new repo + beforeEach (done) -> + fs.remove git_dir, (err) -> + return done err if err + fs.copy "#{__dirname}/fixtures/reset", "#{git_dir}", (err) -> + return done err if err + fs.rename "#{git_dir}/git.git", "#{git_dir}/.git", (err) -> + git.init git_dir, (err) -> + return done err if err + repo = git git_dir + done() + + after (done) -> + fs.remove git_dir, (err) -> + done err + + describe "and create new branch", -> + beforeEach (done) -> + repo.checkout "feature/foo", {b: true}, -> + repo.branch (err, _head) -> + head = _head + done err + + it "should succeed", -> + head.name.should.equal "feature/foo" + describe "#checkoutFile", -> repo = null git_dir = __dirname + "/fixtures/junk_checkoutFile" From eaf7a6f2ee80fad2fa95397ee6ed96e7e3f2e0e8 Mon Sep 17 00:00:00 2001 From: Louis De Bevere Date: Wed, 9 Mar 2016 12:01:59 +0100 Subject: [PATCH 2/3] Improve tests --- test/repo.test.coffee | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/repo.test.coffee b/test/repo.test.coffee index 69014f0..e4b4de2 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -697,9 +697,23 @@ describe "Repo", -> fs.remove git_dir, (err) -> done err + describe "an existing branch", -> + beforeEach (done) -> + repo.checkout "feature/foo", {b: true}, (err) -> + return done err if err? + repo.checkout "master", (err) -> + return done err if err? + repo.branch (err, _head) -> + head = _head + done err + + it "should succeed", -> + head.name.should.equal "master" + describe "and create new branch", -> beforeEach (done) -> - repo.checkout "feature/foo", {b: true}, -> + repo.checkout "feature/foo", {b: true}, (err) -> + return done err if err? repo.branch (err, _head) -> head = _head done err From 17a234f4296be1446318000b3533b6e01dd7cc9d Mon Sep 17 00:00:00 2001 From: Louis De Bevere Date: Wed, 9 Mar 2016 12:12:29 +0100 Subject: [PATCH 3/3] Update readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f575b54..849e37d 100644 --- a/README.md +++ b/README.md @@ -193,9 +193,16 @@ Commit some changes. ### `Repo#remove(files, callback)` `git rm ` -### `Repo#checkout(treeish, callback)` +### `Repo#checkout(treeish, [options], callback)` `git checkout ` +Checkout a branch/commit/... + + * `treeish` - Branch or treeish to checkout. + * `options` - + - `b` - `Boolean` to create a new branch + * `callback` - Receives `(err)`. + ### `Repo#checkoutFile([files, options, ]callback)` Checkout some files.