git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diff-files: treat "i-t-a" files as "not-in-index"

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 19, 2020, 21:43 UTC
Message-ID
<xmqqftaqg299.fsf@gitster.c.googlers.com>
In-Reply-To
<20200619093127.GA47528@mail.clickyotomy.dev>
Srinidhi Kaushik <shrinidhi.kaushik@gmail.com> writes:
Show 27 quoted lines
>> > +     git add -N empty not-empty &&
>> > +     git diff-files -p >actual &&
>> > +     hash_e=$(git hash-object empty) &&
>> > +     hash_n=$(git hash-object not-empty) &&
>> > +     cat >expect <<-EOF &&
>> > +     diff --git a/empty b/empty
>> > +     new file mode 100644
>> > +     index 0000000..$(git rev-parse --short $hash_e)
>> > +     diff --git a/not-empty b/not-empty
>> > +     new file mode 100644
>> > +     index 0000000..$(git rev-parse --short $hash_n)
>> > +     --- /dev/null
>> > +     +++ b/not-empty
>> > +     @@ -0,0 +1 @@
>> > +     +$content
>> > +     EOF
>> > +     test_cmp expect actual
>> > +'
>>
>> OK.  Do we want to show what happens when "diff" and "diff --cached"
>> are run with these two "added but not quite added yet" paths to
>> contrast with this new case?
>
> I'm not sure if we want to repeat an older test. The test (which was
> renamed in this patch) in t2203-add-intent.sh: "diff/diff-cached shows
> ita as new/not-new files" is already doing that. Should  the "diff" and
> "diff --cached" steps be appended here again?

No, there is no need to repeat essentially the same test that exists elsewhere. I wonder if it reduces duplication even further if we extend that existing test that checks "diff" and "diff --cached" so that it also checks "diff-files" as well?, instead of adding this new one? The existing one checks diff and diff-cached only with a new non-empty path, and it can use tests with a new empty path at the same time, with a unified "set up" code that is in the early part of the test, e.g.

diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh
index 5bbe8dcce4..cfde790ac7 100755
--- a/t/t2203-add-intent.sh
+++ b/t/t2203-add-intent.sh
@@ -235,7 +235,8 @@ test_expect_success 'double rename detection in status' '
 test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '
 	git reset --hard &&
 	echo new >new-ita &&
-	git add -N new-ita &&
+	: >new-ita-empty &&
+	git add -N new-ita new-ita-empty &&
 	git diff --summary >actual &&
 	...

Then the existing tests can be updated to see not just --summary but
also for the contents like you did in the new test---and another test
that examines what "git diff-files" sees (which is what you added)
can happen in the same test (that way, the same set-up can be reused
for three tests).

Thanks.
Previous: Srinidhi KaushikNext: Srinidhi Kaushik
Message 9 of 12 in “diff-files: treat "i-t-a" files as "not-in-index"”
  1. diff-files: treat "i-t-a" files as "not-in-index"Srinidhi Kaushik, Jun 11, 2020
  2. Junio C HamanoJun 11, 2020
  3. Srinidhi KaushikJun 11, 2020
  4. Srinidhi KaushikJun 18, 2020
  5. Junio C HamanoJun 18, 2020
  6. Junio C HamanoJun 18, 2020
  7. Junio C HamanoJun 18, 2020
  8. Srinidhi KaushikJun 19, 2020
  9. Junio C HamanoJun 19, 2020
  10. diff-files: treat "i-t-a" files as "not-in-index"Srinidhi Kaushik, Jun 20, 2020
  11. Junio C HamanoJun 20, 2020
  12. Johannes SchindelinJun 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.