Skip to content

Commit

Permalink
Status: take new files in account with type 'N'
Browse files Browse the repository at this point in the history
Repo.add: allow option usage to specify --all
  • Loading branch information
feugy committed Sep 15, 2012
1 parent 157e076 commit 6045289
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/repo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
9 changes: 5 additions & 4 deletions src/status.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
57 changes: 57 additions & 0 deletions test/repo.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6045289

Please sign in to comment.