diff --git a/src/index.coffee b/src/index.coffee index f287439..201dc28 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -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}\"" diff --git a/test/index.test.coffee b/test/index.test.coffee index 4166ad4..711007c 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -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