Skip to content

Commit

Permalink
Maintaining backward compatibility in clone() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
notatestuser committed Nov 16, 2015
1 parent d099f2f commit ab4de66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ Git.init = (path, bare, callback) ->
# callback - Receives `(err, repo)`.
#
Git.clone = (repository, path, depth = 0, callback) ->
if (0 == depth)
if typeof depth is 'function'
callback = depth
depth = 0
if depth is 0 or typeof depth isnt 'number'
bash = "git clone \"#{repository}\" \"#{path}\""
else
bash = "git clone \"#{repository}\" \"#{path}\" --depth \"#{depth}\""
Expand Down
16 changes: 16 additions & 0 deletions test/index.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ describe "git", ->
@timeout 30000
repo = null
newRepositoryDir = "#{__dirname}/fixtures/clone"
before (done) ->
git.clone "https://github.com/notatestuser/gift.git", newRepositoryDir, (err, _repo) ->
repo = _repo
done err
it "clone a repository", (done) ->
repo.should.be.an.instanceof Repo
repo.remote_list (err, remotes) ->
remotes.should.have.length 1
done()
after (done) ->
exec "rm -rf #{newRepositoryDir}", done

describe "clone() with depth", ->
@timeout 30000
repo = null
newRepositoryDir = "#{__dirname}/fixtures/clone_depth"
before (done) ->
git.clone "https://github.com/notatestuser/gift.git", newRepositoryDir, 1, (err, _repo) ->
repo = _repo
Expand Down

0 comments on commit ab4de66

Please sign in to comment.