diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-02-03 09:23:34 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-02-08 02:04:30 +0300 |
commit | a2b7a3b3a966c5801efe968d4b5656fa5a885409 (patch) | |
tree | 10fa9f1407f71ccec95459533dddf9c956f3559d /t/t4013-diff-various.sh | |
parent | 2e9c8789b7b0d4d3cd2f951e1694387686e2d740 (diff) |
diff: support --cached on unborn branches
"git diff --cached" (without revision) used to mean "git diff --cached
HEAD" (i.e. the user was too lazy to type HEAD). This "correctly"
failed when there was no commit yet. But was that correctness useful?
This patch changes the definition of what particular command means.
It is a request to show what _would_ be committed without further "git
add". The internal implementation is the same "git diff --cached HEAD"
when HEAD exists, but when there is no commit yet, it compares the index
with an empty tree object to achieve the desired result.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4013-diff-various.sh')
-rwxr-xr-x | t/t4013-diff-various.sh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 9a66520588..b8f81d07c3 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -290,4 +290,15 @@ test_expect_success 'log -S requires an argument' ' test_must_fail git log -S ' +test_expect_success 'diff --cached on unborn branch' ' + echo ref: refs/heads/unborn >.git/HEAD && + git diff --cached >result && + test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result +' + +test_expect_success 'diff --cached -- file on unborn branch' ' + git diff --cached -- file0 >result && + test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result +' + test_done |