From d099f2fab23bf3c907ed1d702537b189a1c08b83 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 16 Nov 2015 15:18:22 +0800 Subject: [PATCH] Support git's shallow clone --- README.md | 2 +- src/index.coffee | 8 ++++++-- test/index.test.coffee | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 565ed6c..14fb13f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Clone a repository: git = require 'gift' - git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", (err, _repo) -> + git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", depth, (err, _repo) -> repo = _repo # => # diff --git a/src/index.coffee b/src/index.coffee index 307f2c8..f287439 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -32,10 +32,14 @@ Git.init = (path, bare, callback) -> # # repository - The repository to clone from. # path - The directory to clone into. +# depth - The specified number of revisions of shallow clone # callback - Receives `(err, repo)`. # -Git.clone = (repository, path, callback) -> - bash = "git clone \"#{repository}\" \"#{path}\"" +Git.clone = (repository, path, depth = 0, callback) -> + if (0 == depth) + bash = "git clone \"#{repository}\" \"#{path}\"" + else + bash = "git clone \"#{repository}\" \"#{path}\" --depth \"#{depth}\"" exec bash, (err, stdout, stderr) -> return callback err if err return callback err, (new Repo path, false, { maxBuffer: Git.maxBuffer }) diff --git a/test/index.test.coffee b/test/index.test.coffee index af59585..4166ad4 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -45,7 +45,7 @@ describe "git", -> repo = null newRepositoryDir = "#{__dirname}/fixtures/clone" before (done) -> - git.clone "https://github.com/notatestuser/gift.git", newRepositoryDir, (err, _repo) -> + git.clone "https://github.com/notatestuser/gift.git", newRepositoryDir, 1, (err, _repo) -> repo = _repo done err it "clone a repository", (done) ->