From 18bc76164dbf4f6d54b8fa9c9c29db9ca66c7877 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 13 Feb 2008 05:50:51 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- t/t3701-add-interactive.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 t/t3701-add-interactive.sh (limited to 't/t3701-add-interactive.sh') diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh new file mode 100755 index 0000000000..c8dc1ac241 --- /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 output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <output && + sed -ne "/new file/,/content/p" 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 output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <output && + sed -ne "/^index/,/content/p" diff && + diff -u expected diff +' +test_expect_success 'revert works (commit)' ' + git add file && + (echo r; echo 1) | git add -i && + git add -i output && + grep "unchanged *+3/-0 file" output +' + +test_done -- cgit v1.2.1