diff options
author | Jeff King <peff@peff.net> | 2008-02-13 05:50:51 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-02-16 01:02:44 -0800 |
commit | 18bc76164dbf4f6d54b8fa9c9c29db9ca66c7877 (patch) | |
tree | 3aee5a6be8dd3c05d8db162cf4ba61c5dca30d3c /t | |
parent | 346245a1bb6272dd370ba2f7b9bf86d3df5fed9a (diff) | |
download | git-18bc76164dbf4f6d54b8fa9c9c29db9ca66c7877.tar.gz git-18bc76164dbf4f6d54b8fa9c9c29db9ca66c7877.tar.xz |
add--interactive: handle initial commit better
There were several points where we looked at the HEAD
commit; for initial commits, this is meaningless. So instead
we:
- show staged status data as a diff against the empty tree
instead of HEAD
- show file diffs as creation events
- use "git rm --cached" to revert instead of going back to
the HEAD commit
We magically reference the empty tree to implement this.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t3701-add-interactive.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh new file mode 100755 index 000000000..c8dc1ac24 --- /dev/null +++ b/t/t3701-add-interactive.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +test_description='add -i basic tests' +. ./test-lib.sh + +test_expect_success 'setup (initial)' ' + echo content >file && + git add file && + echo more >>file && + echo lines >>file +' +test_expect_success 'status works (initial)' ' + git add -i </dev/null >output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <<EOF +new file mode 100644 +index 0000000..d95f3ad +--- /dev/null ++++ b/file +@@ -0,0 +1 @@ ++content +EOF +test_expect_success 'diff works (initial)' ' + (echo d; echo 1) | git add -i >output && + sed -ne "/new file/,/content/p" <output >diff && + diff -u expected diff +' +test_expect_success 'revert works (initial)' ' + git add file && + (echo r; echo 1) | git add -i && + git ls-files >output && + ! grep . output +' + +test_expect_success 'setup (commit)' ' + echo baseline >file && + git add file && + git commit -m commit && + echo content >>file && + git add file && + echo more >>file && + echo lines >>file +' +test_expect_success 'status works (commit)' ' + git add -i </dev/null >output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <<EOF +index 180b47c..b6f2c08 100644 +--- a/file ++++ b/file +@@ -1 +1,2 @@ + baseline ++content +EOF +test_expect_success 'diff works (commit)' ' + (echo d; echo 1) | git add -i >output && + sed -ne "/^index/,/content/p" <output >diff && + diff -u expected diff +' +test_expect_success 'revert works (commit)' ' + git add file && + (echo r; echo 1) | git add -i && + git add -i </dev/null >output && + grep "unchanged *+3/-0 file" output +' + +test_done |