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

Re: [PATCH 1/2] t3312-notes-empty: Test that 'git notes' removes empty notes by default

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 5, 2014, 04:10 UTC
Message-ID
<CAPig+cT4-1bY5tq8KioC8Js3ZUfZCuFEwOZMeoPW4M_brK+QXw@mail.gmail.com>
In-Reply-To
<1415151175-1682-1-git-send-email-johan@herland.net>
On Tue, Nov 4, 2014 at 8:32 PM, Johan Herland <johan@herland.net> wrote:
Show 27 quoted lines
> Add test cases documenting the current behavior when trying to
> add/append/edit empty notes. This is in preparation for adding
> --allow-empty; to allow empty notes to be stored.
>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
>  t/t3312-notes-empty.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
>  create mode 100755 t/t3312-notes-empty.sh
>
> diff --git a/t/t3312-notes-empty.sh b/t/t3312-notes-empty.sh
> new file mode 100755
> index 0000000..2806d27
> --- /dev/null
> +++ b/t/t3312-notes-empty.sh
> @@ -0,0 +1,58 @@
> +#!/bin/sh
> +
> +test_description='Test adding/editing of empty notes'
> +. ./test-lib.sh
> +
> +cat >fake_editor.sh <<\EOF
> +#!/bin/sh
> +echo "$MSG" >"$1"
> +echo "$MSG" >& 2
> +EOF
> +chmod a+x fake_editor.sh
write_script() would allow you to drop the #!/bin/sh and chmod lines.
Show 19 quoted lines
> +GIT_EDITOR=./fake_editor.sh
> +export GIT_EDITOR
> +
> +test_expect_success 'setup' '
> +       test_commit one &&
> +       empty_blob=$(git hash-object -w /dev/null)
> +'
> +
> +cleanup_notes() {
> +       git update-ref -d refs/notes/commits
> +}
> +
> +cat >expect_missing <<\EOF
> +commit d79ce1670bdcb76e6d1da2ae095e890ccb326ae9
> +Author: A U Thor <author@example.com>
> +Date:   Thu Apr 7 15:13:13 2005 -0700
> +
> +    one
> +EOF

Rather than hard-coding this output, generating it would make the test script less fragile:

    git log -1 >expect_missing
Show 25 quoted lines
> +verify_missing() {
> +       git log -1 > actual &&
> +       test_cmp expect_missing actual &&
> +       ! git notes list HEAD
> +}
> +
> +for cmd in \
> +       'add' \
> +       'add -F /dev/null' \
> +       'add -m ""' \
> +       'add -c "$empty_blob"' \
> +       'add -C "$empty_blob"' \
> +       'append' \
> +       'append -F /dev/null' \
> +       'append -m ""' \
> +       'append -c "$empty_blob"' \
> +       'append -C "$empty_blob"' \
> +       'edit'
> +do
> +       test_expect_success "'git notes $cmd' removes empty note" "
> +               cleanup_notes &&
> +               MSG= git notes $cmd &&
> +               verify_missing
> +       "
> +done
Each -c/-C case fails for me when trying to read $empty_object. For example:

fatal: Failed to read object 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'. not ok 5 - 'git notes add -c "$empty_blob"' removes empty note

> +
> +test_done
> --
> 2.0.0.rc4.501.gdaf83ca
Previous: Johan HerlandNext: Johan Herland
Message 3 of 5 in “t3312-notes-empty: Test that 'git notes' removes empty notes by default”
  1. 1/2 t3312-notes-empty: Test that 'git notes' removes empty notes by defaultJohan Herland, Nov 5, 2014
  2. 2/2 notes: Add --allow-empty, to allow storing empty notesJohan Herland, Nov 5, 2014
  3. Eric SunshineNov 5, 2014
  4. Johan HerlandNov 5, 2014
  5. Junio C HamanoNov 5, 2014

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.