Skip to content

Commit

Permalink
- Repo.commit: possibility to specify author
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Sep 14, 2012
1 parent 1ed5081 commit 6fb57d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/repo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,15 @@ module.exports = class Repo
# options - Object (optional).
# "amend" - Boolean
# "all" - Boolean
# "author"- String formated like: A U Thor <[email protected]>
# callback - Receives `(err)`.
#
commit: (message, options, callback) ->
[options, callback] = [callback, options] if !callback
options ?= {}
options = _.extend options, {m: "\"#{message}\""}
# add quotes around author
options.author = "\"#{options.author}\"" if options.author?
@git "commit", options, callback

# Public: Add files to the index.
Expand Down
35 changes: 35 additions & 0 deletions test/repo.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,41 @@ describe "Repo", ->
commits[0].message.should.include "commit 4"


describe "#commit", ->
repo = null
commit = null
git_dir = __dirname + "/fixtures/junk_commit"
# given a fresh new repo
before (done) ->
rimraf git_dir, (err) ->
return done err if err
fs.mkdir git_dir, '0755', (err) ->
return done err if err
git.init git_dir, (err) ->
return done err if err
repo = git(git_dir)
fs.writeFileSync "#{git_dir}/foo.txt", "cheese"
repo.add "#{git_dir}/foo.txt", (err) ->
return done err if err
repo.commit 'message with spaces',
all:true
author: 'Someone <[email protected]>'
, (err) ->
return done err if err
repo.commits (err, _commits) ->
commit = _commits[0]
done err

after (done) ->
rimraf git_dir, done

it "has right message", (done) ->
commit.message.should.eql 'message with spaces'
commit.author.name.should.eql 'Someone'
commit.author.email.should.eql '[email protected]'
done()


describe "#tree", ->
repo = fixtures.branched
describe "master", ->
Expand Down

0 comments on commit 6fb57d6

Please sign in to comment.