1
0
mirror of https://github.com/danog/gift.git synced 2024-11-26 20:04:47 +01:00

Merge pull request #84 from asgoth/feature/checkout-pass-options

Pass options to checkout command
This commit is contained in:
Luke Plaster 2016-03-12 19:03:08 +08:00
commit 576e8d04f4
3 changed files with 60 additions and 3 deletions

View File

@ -193,9 +193,16 @@ Commit some changes.
### `Repo#remove(files, callback)`
`git rm <files>`
### `Repo#checkout(treeish, callback)`
### `Repo#checkout(treeish, [options], callback)`
`git checkout <treeish>`
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.

View File

@ -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
#

View File

@ -676,6 +676,51 @@ 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 "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}, (err) ->
return done err if err?
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"