Skip to content

Commit

Permalink
Git.init() extended with bare parameter
Browse files Browse the repository at this point in the history
* When bare parameter is set to true, bare repository is initialized.
* Tests added for bare and non-bare initialization.
* Documentaiton updated.
  • Loading branch information
skovalyov committed Sep 23, 2013
1 parent a197fe7 commit b71c18f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@ A simple Node.js wrapper for the Git CLI. The API is based on

# API

For existing repositories:

git = require 'gift'

repo = git "path/to/repo"
# => #<Repo>

Initialize a new repository:

git = require 'gift'

git.init "path/to/repo", (err, _repo) ->
repo = _repo
# => #<Repo>

Initialize a new bare repository:

git = require 'gift'

git.init "path/to/bare/repo", true, (err, _repo) ->
repo = _repo
# => #<Repo>

Clone a repository:

Expand Down
12 changes: 9 additions & 3 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ module.exports = Git = (path, bare=false) ->
# Public: Initialize a git repository.
#
# path - The directory to run `git init .` in.
# bare - Create a bare repository when true.
# callback - Receives `(err, repo)`.
#
Git.init = (path, callback) ->
exec "git init .", {cwd: path}
Git.init = (path, bare, callback) ->
[bare, callback] = [callback, bare] if !callback
if bare
bash = "git init --bare ."
else
bash = "git init ."
exec bash, {cwd: path}
, (err, stdout, stderr) ->
return callback err if err
return callback err, (new Repo path)
return callback err, (new Repo path, bare)

# Public: Clone a git repository.
#
Expand Down
32 changes: 31 additions & 1 deletion test/index.test.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
should = require 'should'
git = require '../src'
Repo = require '../src/repo'
fs = require "fs"
{exec} = require 'child_process'

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

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

describe "init()", ->
repo = null
newRepositoryDir = "#{__dirname}/fixtures/new"
before (done) ->
fs.mkdirSync newRepositoryDir
git.init newRepositoryDir, (err, _repo) ->
repo = _repo
done err
it "inits a Repo", ->
repo.should.be.an.instanceof Repo
bare = repo.bare || false
bare.should.be.false
after (done) ->
exec "rm -rf #{newRepositoryDir}", done

describe "init() bare", ->
repo = null
newRepositoryDir = "#{__dirname}/fixtures/bare"
before (done) ->
fs.mkdirSync newRepositoryDir
git.init newRepositoryDir, true, (err, _repo) ->
repo = _repo
done err
it "inits a bare Repo", ->
repo.should.be.an.instanceof Repo
bare = repo.bare || false
bare.should.be.true
after (done) ->
exec "rm -rf #{newRepositoryDir}", done

describe "clone()", ->
@timeout 30000
repo = null
Expand Down

0 comments on commit b71c18f

Please sign in to comment.