Skip to content

Commit

Permalink
Support git's shallow clone
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Nov 16, 2015
1 parent e414fc5 commit d099f2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# => #<Repo>

Expand Down
8 changes: 6 additions & 2 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
2 changes: 1 addition & 1 deletion test/index.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down

0 comments on commit d099f2f

Please sign in to comment.