diff: support --cached on unborn branches
commita2b7a3b3a966c5801efe968d4b5656fa5a885409
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 3 Feb 2011 06:23:34 +0000 (3 13:23 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Feb 2011 23:04:30 +0000 (7 15:04 -0800)
tree10fa9f1407f71ccec95459533dddf9c956f3559d
parent2e9c8789b7b0d4d3cd2f951e1694387686e2d740
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>
Documentation/git-diff.txt
builtin/diff.c
t/t4013-diff-various.sh
t/t4013/diff.diff_--cached [new file with mode: 0644]
t/t4013/diff.diff_--cached_--_file0 [new file with mode: 0644]