Skip to content

Commit

Permalink
Merge pull request #42 from PeterDaveHello/add_git_pull_support
Browse files Browse the repository at this point in the history
add git pull basic support
  • Loading branch information
notatestuser committed Nov 16, 2015
2 parents 92c77b8 + 874b01d commit 8b34419
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ Clone a repository:
repo = _repo
# => #<Repo>

Pull a repository:

git = require 'gift'

git.pull "remote", "branch", "path/to/local/pull/repo", (err, _repo) ->
repo = _repo
# => #<Repo>


## Repo
### `Repo#path`
`String` - The path to the repository.
Expand Down
22 changes: 22 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,25 @@ Git.clone = (repository, path, depth = 0, callback) ->
exec bash, (err, stdout, stderr) ->
return callback err if err
return callback err, (new Repo path, false, { maxBuffer: Git.maxBuffer })

# Public: Pull a git repository.
#
# remote - The remote to pull from.
# branch - The branch to pull from.
# path - The directory to pull into.
# callback - Receives `(err, repo)`.
#
Git.pull = (remote = '', branch = '', path = '', callback) ->
if (remote == '' || branch == '')
if (path == '')
bash = "git pull"
else
bash = "git -C #{path} pull"
else
if (path == '')
bash = "git pull #{remote} #{branch}"
else
bash = "git -C #{path} pull #{remote} #{branch}"
exec bash, (err, stdout, stderr) ->
return callback err if err
return callback err, (new Repo path)
15 changes: 15 additions & 0 deletions test/index.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@ describe "git", ->
done()
after (done) ->
exec "rm -rf #{newRepositoryDir}", done

describe "pull()", ->
@timeout 30000
repo = null
RepositoryDir = "#{__dirname}/fixtures/clone"
before (done) ->
git.clone "https://github.com/notatestuser/gift.git", RepositoryDir, (err, _repo) ->
git.pull '', '', RepositoryDir, (err, _repo) ->
repo = _repo
done err
it "pull a repository", (done) ->
repo.should.be.an.instanceof Repo
done()
after (done) ->
exec "rm -rf #{RepositoryDir}", done

0 comments on commit 8b34419

Please sign in to comment.