Skip to content

Commit

Permalink
Git.clone() added
Browse files Browse the repository at this point in the history
* Wrapper for `git clone` command.
* Test added and custom 30000 timeout is set to it as cloning requires
quite some time.
* Documentation updated.
  • Loading branch information
skovalyov committed Sep 23, 2013
1 parent 9503fc8 commit a197fe7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ A simple Node.js wrapper for the Git CLI. The API is based on
repo = git "path/to/repo"
# => #<Repo>


Clone a repository:

git = require 'gift'

git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", (err, _repo) ->
repo = _repo
# => #<Repo>

## Repo
### `Repo#path`
`String` - The path to the repository.
Expand Down
12 changes: 12 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ Git.init = (path, callback) ->
, (err, stdout, stderr) ->
return callback err if err
return callback err, (new Repo path)

# Public: Clone a git repository.
#
# repository - The repository to clone from.
# path - The directory to clone into.
# callback - Receives `(err, repo)`.
#
Git.clone = (repository, path, callback) ->
bash = "git clone #{repository} #{path}"
exec bash, (err, stdout, stderr) ->
return callback err if err
return callback err, (new Repo path)
17 changes: 17 additions & 0 deletions test/index.test.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
should = require 'should'
git = require '../src'
Repo = require '../src/repo'
{exec} = require 'child_process'

describe "git", ->
describe "()", ->
repo = git "#{__dirname}/fixtures/simple"

it "returns a Repo", ->
repo.should.be.an.instanceof Repo

describe "clone()", ->
@timeout 30000
repo = null
newRepositoryDir = "#{__dirname}/fixtures/clone"
before (done) ->
git.clone "[email protected]:sentientwaffle/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

0 comments on commit a197fe7

Please sign in to comment.