All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] diff: support --root --cached combination
@ 2010-10-29  9:54 Nguyễn Thái Ngọc Duy
  2010-10-29 10:19 ` Jonathan Nieder
  2010-10-29 15:40 ` [PATCH] diff: support --root --cached combination Jeff King
  0 siblings, 2 replies; 9+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-10-29  9:54 UTC (permalink / raw)
  To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I have a ritual of doing "git dic" (short for diff --cached) before
 committing and does not want to break it, even on new repos.

 Looks like a good thing and no harm to the rest of the world.

 builtin/diff.c              |    9 +++++++--
 t/t4046-diff-cached-root.sh |   31 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100755 t/t4046-diff-cached-root.sh

diff --git a/builtin/diff.c b/builtin/diff.c
index a43d326..45be6f3 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -330,8 +330,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 			else if (!strcmp(arg, "--cached") ||
 				 !strcmp(arg, "--staged")) {
 				add_head_to_pending(&rev);
-				if (!rev.pending.nr)
-					die("No HEAD commit to compare with (yet)");
+				if (!rev.pending.nr) {
+					struct object *obj;
+					if (!rev.show_root_diff)
+						die("No HEAD commit to compare with (yet)");
+					obj = (struct object*)lookup_tree((unsigned char*)EMPTY_TREE_SHA1_BIN);
+					add_pending_object(&rev, obj, "HEAD");
+				}
 				break;
 			}
 		}
diff --git a/t/t4046-diff-cached-root.sh b/t/t4046-diff-cached-root.sh
new file mode 100755
index 0000000..82e3ad8
--- /dev/null
+++ b/t/t4046-diff-cached-root.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+test_description='git diff --cached --root test'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	echo cached >file &&
+	git add file &&
+	echo not-cached >>file
+'
+
+test_expect_success 'diff --cached' '
+	test_must_fail git diff --cached
+'
+
+test_expect_success 'diff --cached --root' '
+	git diff --cached --root >result &&
+	cat >expected <<\EOF &&
+diff --git a/file b/file
+new file mode 100644
+index 0000000..ec9a961
+--- /dev/null
++++ b/file
+@@ -0,0 +1 @@
++cached
+EOF
+	test_cmp expected result
+'
+
+test_done
-- 
1.7.0.2.445.gcbdb3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] diff: support --root --cached combination
  2010-10-29  9:54 [PATCH] diff: support --root --cached combination Nguyễn Thái Ngọc Duy
@ 2010-10-29 10:19 ` Jonathan Nieder
  2010-10-29 11:00   ` Nguyen Thai Ngoc Duy
  2010-10-29 17:06   ` Junio C Hamano
  2010-10-29 15:40 ` [PATCH] diff: support --root --cached combination Jeff King
  1 sibling, 2 replies; 9+ messages in thread
From: Jonathan Nieder @ 2010-10-29 10:19 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano

Nguyễn Thái Ngọc Duy wrote:

>  I have a ritual of doing "git dic" (short for diff --cached) before
>  committing and does not want to break it, even on new repos.
> 
>  Looks like a good thing and no harm to the rest of the world.

This explanation belongs in the commit message, methinks.

> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -330,8 +330,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
>  			else if (!strcmp(arg, "--cached") ||
>  				 !strcmp(arg, "--staged")) {
>  				add_head_to_pending(&rev);
> -				if (!rev.pending.nr)
> -					die("No HEAD commit to compare with (yet)");
> +				if (!rev.pending.nr) {
> +					struct object *obj;
> +					if (!rev.show_root_diff)
> +						die("No HEAD commit to compare with (yet)");

How does this condition get tripped?  The code allowing "[log]
showroot" to be set to false is only invoked by the log family of
commands.

Using --root as the backward-compatibility option seems like
an abuse of language, anyway.  "git diff --cached" has two
meanings:

 1. show changes to be committed

    1b. show what git show --format=" " would say after a commit

 2. show differences between the index and the commit named by the
    (implicit) HEAD argument

With interpretation (1b), --root should be respected, and the output
should be empty (!), not an error, when "[log] showroot" is false.

With interpretation (2), --root should not be respected, and an
attempt to diff --cached in an unborn branch should be an error.

(1a) and (1b) are the only useful interpretations.  So for simplicity,
would it make sense to drop the "if ()" for --root and make

> +test_expect_success 'diff --cached' '
> +	test_must_fail git diff --cached
> +'

fail?

> +					obj = (struct object*)lookup_tree((unsigned char*)EMPTY_TREE_SHA1_BIN);

	struct tree *tree = lookup_tree((const unsigned char *) ...
	obj = &tree->object;

might be more clear (and robust against future layout changes).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] diff: support --root --cached combination
  2010-10-29 10:19 ` Jonathan Nieder
@ 2010-10-29 11:00   ` Nguyen Thai Ngoc Duy
  2010-10-29 17:06   ` Junio C Hamano
  1 sibling, 0 replies; 9+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-10-29 11:00 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, Junio C Hamano

2010/10/29 Jonathan Nieder <jrnieder@gmail.com>:
>> --- a/builtin/diff.c
>> +++ b/builtin/diff.c
>> @@ -330,8 +330,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
>>                       else if (!strcmp(arg, "--cached") ||
>>                                !strcmp(arg, "--staged")) {
>>                               add_head_to_pending(&rev);
>> -                             if (!rev.pending.nr)
>> -                                     die("No HEAD commit to compare with (yet)");
>> +                             if (!rev.pending.nr) {
>> +                                     struct object *obj;
>> +                                     if (!rev.show_root_diff)
>> +                                             die("No HEAD commit to compare with (yet)");
>
> How does this condition get tripped?  The code allowing "[log]
> showroot" to be set to false is only invoked by the log family of
> commands.
>
> Using --root as the backward-compatibility option seems like
> an abuse of language, anyway.

Hmm.. I thought --root was supported by all diff command family. Now I
think of it, only "diff-tree --root" makes sense.

>  "git diff --cached" has two meanings:
>
>  1. show changes to be committed
>
>    1b. show what git show --format=" " would say after a commit
>
>  2. show differences between the index and the commit named by the
>    (implicit) HEAD argument
>
> With interpretation (1b), --root should be respected, and the output
> should be empty (!), not an error, when "[log] showroot" is false.
>
> With interpretation (2), --root should not be respected, and an
> attempt to diff --cached in an unborn branch should be an error.

If you commit to an unborn branch, it would become the first commit of
that branch. So by (1a), it should show what is to be commited, isn't
it?

>
> (1a) and (1b) are the only useful interpretations.  So for simplicity,
> would it make sense to drop the "if ()" for --root and make
>
>> +test_expect_success 'diff --cached' '
>> +     test_must_fail git diff --cached
>> +'
>
> fail?

All for simpler, yes.

>
>> +                                     obj = (struct object*)lookup_tree((unsigned char*)EMPTY_TREE_SHA1_BIN);
>
>        struct tree *tree = lookup_tree((const unsigned char *) ...
>        obj = &tree->object;
>
> might be more clear (and robust against future layout changes).
>

OK

-- 
Duy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] diff: support --root --cached combination
  2010-10-29  9:54 [PATCH] diff: support --root --cached combination Nguyễn Thái Ngọc Duy
  2010-10-29 10:19 ` Jonathan Nieder
@ 2010-10-29 15:40 ` Jeff King
  1 sibling, 0 replies; 9+ messages in thread
From: Jeff King @ 2010-10-29 15:40 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano

On Fri, Oct 29, 2010 at 04:54:47PM +0700, Nguyễn Thái Ngọc Duy wrote:

> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  I have a ritual of doing "git dic" (short for diff --cached) before
>  committing and does not want to break it, even on new repos.
> 
>  Looks like a good thing and no harm to the rest of the world.

Hmm. What's new is old, I suppose. You might want to read the comments
on my very similar patch here:

  http://thread.gmane.org/gmane.comp.version-control.git/95935/focus=96187

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] diff: support --root --cached combination
  2010-10-29 10:19 ` Jonathan Nieder
  2010-10-29 11:00   ` Nguyen Thai Ngoc Duy
@ 2010-10-29 17:06   ` Junio C Hamano
  2010-10-30 11:16     ` [PATCH v2] diff: support --cached on unborn branches Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-10-29 17:06 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Nguyễn Thái Ngọc Duy, git

Jonathan Nieder <jrnieder@gmail.com> writes:

> Using --root as the backward-compatibility option seems like
> an abuse of language, anyway.  "git diff --cached" has two
> meanings:
>
>  1. show changes to be committed
>
>     1b. show what git show --format=" " would say after a commit
>
>  2. show differences between the index and the commit named by the
>     (implicit) HEAD argument
>
> With interpretation (1b), --root should be respected, and the output
> should be empty (!), not an error, when "[log] showroot" is false.
>
> With interpretation (2), --root should not be respected, and an
> attempt to diff --cached in an unborn branch should be an error.
>
> (1a) and (1b) are the only useful interpretations.  So for simplicity,
> would it make sense to drop the "if ()" for --root and make
>
>> +test_expect_success 'diff --cached' '
>> +	test_must_fail git diff --cached
>> +'
>
> fail?

I don't see 1a up above, but I agree.

Let's explain the patch this way (yes, I am writing a proposed commit log
message Duy should have written):

    "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 still 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.

Unlike "diff-index --cached HEAD" that must fail when HEAD does not name a
valid rev, we do not have to be so strict in "git diff" Porcelain,
especially when the end user does not even explicitly say HEAD.

To put it in another way, we should strive to define the behaviour of the
plumbing precisely in terms of the mechanism and machinery (e.g. if you
ask for an operation between a tree and the index, and if you incorrectly
specified the tree, you _should_ get an error, instead of a result that
somebody randomly chose, saying "we thought it would be more useful for
you this way").  But we should try to define the behaviour of the
Porcelain commands in terms of the use case and the workflow we try to
encourage and support.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] diff: support --cached on unborn branches
  2010-10-29 17:06   ` Junio C Hamano
@ 2010-10-30 11:16     ` Nguyễn Thái Ngọc Duy
  2010-10-31  3:12       ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-10-30 11:16 UTC (permalink / raw)
  To: git, Junio C Hamano, Jonathan Niedier, Jeff King
  Cc: Nguyễn Thái Ngọc Duy

"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 still 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.

(Written by Junio)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 "git diff --cached HEAD" does fail, but I don't really care.

 builtin/diff.c                      |    7 ++++-
 t/t4013-diff-various.sh             |   11 ++++++++++
 t/t4013/diff.diff_--cached          |   38 +++++++++++++++++++++++++++++++++++
 t/t4013/diff.diff_--cached_--_file0 |   15 +++++++++++++
 4 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 t/t4013/diff.diff_--cached
 create mode 100644 t/t4013/diff.diff_--cached_--_file0

diff --git a/builtin/diff.c b/builtin/diff.c
index a43d326..d8db957 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -330,8 +330,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 			else if (!strcmp(arg, "--cached") ||
 				 !strcmp(arg, "--staged")) {
 				add_head_to_pending(&rev);
-				if (!rev.pending.nr)
-					die("No HEAD commit to compare with (yet)");
+				if (!rev.pending.nr) {
+					struct tree *tree;
+					tree = lookup_tree((const unsigned char*)EMPTY_TREE_SHA1_BIN);
+					add_pending_object(&rev, &tree->object, "HEAD");
+				}
 				break;
 			}
 		}
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 9a66520..b8f81d0 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
diff --git a/t/t4013/diff.diff_--cached b/t/t4013/diff.diff_--cached
new file mode 100644
index 0000000..ff16e83
--- /dev/null
+++ b/t/t4013/diff.diff_--cached
@@ -0,0 +1,38 @@
+diff --git a/dir/sub b/dir/sub
+new file mode 100644
+index 0000000..992913c
+--- /dev/null
++++ b/dir/sub
+@@ -0,0 +1,8 @@
++A
++B
++C
++D
++E
++F
++1
++2
+diff --git a/file0 b/file0
+new file mode 100644
+index 0000000..10a8a9f
+--- /dev/null
++++ b/file0
+@@ -0,0 +1,9 @@
++1
++2
++3
++4
++5
++6
++A
++B
++C
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..b1e6722
+--- /dev/null
++++ b/file1
+@@ -0,0 +1,3 @@
++A
++B
++C
diff --git a/t/t4013/diff.diff_--cached_--_file0 b/t/t4013/diff.diff_--cached_--_file0
new file mode 100644
index 0000000..b9bb858
--- /dev/null
+++ b/t/t4013/diff.diff_--cached_--_file0
@@ -0,0 +1,15 @@
+diff --git a/file0 b/file0
+new file mode 100644
+index 0000000..10a8a9f
+--- /dev/null
++++ b/file0
+@@ -0,0 +1,9 @@
++1
++2
++3
++4
++5
++6
++A
++B
++C
-- 
1.7.0.2.445.gcbdb3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] diff: support --cached on unborn branches
  2010-10-30 11:16     ` [PATCH v2] diff: support --cached on unborn branches Nguyễn Thái Ngọc Duy
@ 2010-10-31  3:12       ` Junio C Hamano
  2010-10-31  3:24         ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-10-31  3:12 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, Junio C Hamano, Jonathan Niedier, Jeff King

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> "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 still 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: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

Will take a look at it, and queue.  Thanks.

>  "git diff --cached HEAD" does fail, but I don't really care.

I _do_ care, and so should you.  And I think it _should_ fail, if the user
explicitly asked to compare the index with HEAD that does not exist yet.

As we are updating the semantics of a Porcelain command, there should be
an update that explains the new usage in the documentation, no?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] diff: support --cached on unborn branches
  2010-10-31  3:12       ` Junio C Hamano
@ 2010-10-31  3:24         ` Nguyen Thai Ngoc Duy
  2011-02-03  6:23           ` [PATCH] " Nguyễn Thái Ngọc Duy
  0 siblings, 1 reply; 9+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-10-31  3:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jonathan Niedier, Jeff King

On Sat, Oct 30, 2010 at 08:12:27PM -0700, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> 
> > "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 still 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: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> 
> Will take a look at it, and queue.  Thanks.
> 
> >  "git diff --cached HEAD" does fail, but I don't really care.
> 
> I _do_ care, and so should you.  And I think it _should_ fail, if the user
> explicitly asked to compare the index with HEAD that does not exist yet.
> 
> As we are updating the semantics of a Porcelain command, there should be
> an update that explains the new usage in the documentation, no?

Yes.

--8<--
diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index dd1fb32..518e46b 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -32,7 +32,9 @@ directories. This behavior can be forced by --no-index.
 	This form is to view the changes you staged for the next
 	commit relative to the named <commit>.  Typically you
 	would want comparison with the latest commit, so if you
-	do not give <commit>, it defaults to HEAD.
+	do not give <commit>, it defaults to HEAD. If HEAD does
+	not exist (e.g. unborn branches) and <commit> is not
+	given, it shows all staged changes.
 	--staged is a synonym of --cached.
 
 'git diff' [--options] <commit> [--] [<path>...]::
--8<--
-- 
Duy

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] diff: support --cached on unborn branches
  2010-10-31  3:24         ` Nguyen Thai Ngoc Duy
@ 2011-02-03  6:23           ` Nguyễn Thái Ngọc Duy
  0 siblings, 0 replies; 9+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-02-03  6:23 UTC (permalink / raw)
  To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy

"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 still 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.

(Written by Junio)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 (Good) old stuff. I think it wasn't accepted because I was lazy in
 updating docs. Resend (with doc updates).

 Documentation/git-diff.txt          |    2 +
 builtin/diff.c                      |    7 ++++-
 t/t4013-diff-various.sh             |   11 ++++++++++
 t/t4013/diff.diff_--cached          |   38 +++++++++++++++++++++++++++++++++++
 t/t4013/diff.diff_--cached_--_file0 |   15 +++++++++++++
 5 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 t/t4013/diff.diff_--cached
 create mode 100644 t/t4013/diff.diff_--cached_--_file0

diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index f6ac847..4910510 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -38,6 +38,8 @@ directories. This behavior can be forced by --no-index.
 	commit relative to the named <commit>.  Typically you
 	would want comparison with the latest commit, so if you
 	do not give <commit>, it defaults to HEAD.
+	If HEAD does not exist (e.g. unborned branches) and
+	<commit> is not given, it shows all staged changes.
 	--staged is a synonym of --cached.
 
 'git diff' [--options] <commit> [--] [<path>...]::
diff --git a/builtin/diff.c b/builtin/diff.c
index 945e758..42822cd 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -330,8 +330,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 			else if (!strcmp(arg, "--cached") ||
 				 !strcmp(arg, "--staged")) {
 				add_head_to_pending(&rev);
-				if (!rev.pending.nr)
-					die("No HEAD commit to compare with (yet)");
+				if (!rev.pending.nr) {
+					struct tree *tree;
+					tree = lookup_tree((const unsigned char*)EMPTY_TREE_SHA1_BIN);
+					add_pending_object(&rev, &tree->object, "HEAD");
+				}
 				break;
 			}
 		}
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 9a66520..b8f81d0 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
diff --git a/t/t4013/diff.diff_--cached b/t/t4013/diff.diff_--cached
new file mode 100644
index 0000000..ff16e83
--- /dev/null
+++ b/t/t4013/diff.diff_--cached
@@ -0,0 +1,38 @@
+diff --git a/dir/sub b/dir/sub
+new file mode 100644
+index 0000000..992913c
+--- /dev/null
++++ b/dir/sub
+@@ -0,0 +1,8 @@
++A
++B
++C
++D
++E
++F
++1
++2
+diff --git a/file0 b/file0
+new file mode 100644
+index 0000000..10a8a9f
+--- /dev/null
++++ b/file0
+@@ -0,0 +1,9 @@
++1
++2
++3
++4
++5
++6
++A
++B
++C
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..b1e6722
+--- /dev/null
++++ b/file1
+@@ -0,0 +1,3 @@
++A
++B
++C
diff --git a/t/t4013/diff.diff_--cached_--_file0 b/t/t4013/diff.diff_--cached_--_file0
new file mode 100644
index 0000000..b9bb858
--- /dev/null
+++ b/t/t4013/diff.diff_--cached_--_file0
@@ -0,0 +1,15 @@
+diff --git a/file0 b/file0
+new file mode 100644
+index 0000000..10a8a9f
+--- /dev/null
++++ b/file0
+@@ -0,0 +1,9 @@
++1
++2
++3
++4
++5
++6
++A
++B
++C
-- 
1.7.3.4.878.g439c7

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-02-03  6:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-29  9:54 [PATCH] diff: support --root --cached combination Nguyễn Thái Ngọc Duy
2010-10-29 10:19 ` Jonathan Nieder
2010-10-29 11:00   ` Nguyen Thai Ngoc Duy
2010-10-29 17:06   ` Junio C Hamano
2010-10-30 11:16     ` [PATCH v2] diff: support --cached on unborn branches Nguyễn Thái Ngọc Duy
2010-10-31  3:12       ` Junio C Hamano
2010-10-31  3:24         ` Nguyen Thai Ngoc Duy
2011-02-03  6:23           ` [PATCH] " Nguyễn Thái Ngọc Duy
2010-10-29 15:40 ` [PATCH] diff: support --root --cached combination Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.