1
0
mirror of https://github.com/danog/gift.git synced 2024-11-26 20:04:47 +01:00

Status: take new files in account with type 'N'

Repo.add: allow option usage to specify --all
This commit is contained in:
feugy 2012-09-15 12:36:47 +02:00
parent 157e076125
commit 604528980e
3 changed files with 68 additions and 6 deletions

View File

@ -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.
#

View File

@ -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) ->

View File

@ -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