diff --git a/src/repo.coffee b/src/repo.coffee index 8330e9b..762fff4 100644 --- a/src/repo.coffee +++ b/src/repo.coffee @@ -225,11 +225,15 @@ module.exports = class Repo # Public: Add files to the index. # # files - Array of String paths; or a String path. + # options - Object (optional). + # "all" - Boolean # callback - Receives `(err)`. # - add: (files, callback) -> + add: (files, options, callback) -> + [options, callback] = [callback, options] if !callback + options ?= {} files = [files] if _.isString files - @git "add", {}, files, callback + @git "add", options, files, callback # Public: Remove files from the index. # diff --git a/src/status.coffee b/src/status.coffee index 2ebe241..4d20d1d 100644 --- a/src/status.coffee +++ b/src/status.coffee @@ -20,11 +20,12 @@ BEGIN_UNSTAGED = [ BEGIN_UNTRACKED = [ "# Untracked files:" ] -FILE = /^#\s+([^\s]+)[:]\s+(.+)$/ +FILE = /^#\s+([^:]+)[:]\s+(.+)$/ TYPES = - added: "A" - modified: "M" - deleted: "D" + 'new file': "N" + added: "A" + modified: "M" + deleted: "D" S.Status = class Status constructor: (@repo) -> diff --git a/test/repo.test.coffee b/test/repo.test.coffee index a980805..a98cdab 100644 --- a/test/repo.test.coffee +++ b/test/repo.test.coffee @@ -13,6 +13,63 @@ Status = require '../src/status' {exec} = require 'child_process' describe "Repo", -> + + describe "#add", -> + repo = null + git_dir = __dirname + "/fixtures/junk_add" + status = null + file = null + + # 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 + done() + + after (done) -> + rimraf git_dir, done + + describe "with only a file", -> + file = 'foo.txt' + # given a new file + before (done) -> + fs.writeFile "#{git_dir}/#{file}", "cheese", (err) -> + return done err if err? + repo.add "#{git_dir}/#{file}", (err) -> + return done err if err? + repo.status (err, _status) -> + status = _status + done err + + it "was added", -> + status.files.should.have.a.property file + status.files[file].staged.should.be.true + status.files[file].tracked.should.be.true + status.files[file].type.should.eql 'N' + + describe "with no file and all option", -> + file = 'bar.txt' + # given a new file + before (done) -> + fs.writeFile "#{git_dir}/#{file}", "cheese", (err) -> + return done err if err? + repo.add [], A:true, (err) -> + return done err if err? + repo.status (err, _status) -> + status = _status + done err + + it "was added", -> + status.files.should.have.a.property file + status.files[file].staged.should.be.true + status.files[file].tracked.should.be.true + status.files[file].type.should.eql 'N' + describe "#commits", -> describe "with only a callback", -> repo = fixtures.branched