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

Re: [PATCH] tag: add --edit option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 1, 2018, 10:16 UTC
Message-ID
<CAPig+cTFsp60KB+quuytW_nV2crLcjRV-PYN-3bO7tRY0_xu6w@mail.gmail.com>
In-Reply-To
<450140f4-d410-4f1a-e5c1-c56d345a7f7c@suse.com>

On Thu, Feb 1, 2018 at 4:49 AM, Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com> wrote:

Show 17 quoted lines
> Add a --edit option whichs allows modifying the messages provided by -m or -F,
> the same way git commit --edit does.
>
> Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>
> ---
> diff --git a/builtin/tag.c b/builtin/tag.c
> @@ -224,7 +225,7 @@ static void create_tag(const struct object_id *object, const char *tag,
> -       if (!opt->message_given) {
> +       if (!opt->message_given || opt->use_editor) {
>
> -               if (!is_null_oid(prev)) {
> +               if (opt->message_given) {
> +                       write_or_die(fd, buf->buf, buf->len);
> +                       strbuf_reset(buf);
> +               } else if (!is_null_oid(prev)) {
>                         write_tag_body(fd, prev);
>                 } else {

A little below this change is where launch_editor() is actually invoked. If it fails for some reason, it prints:

    Please supply the message using either -m or -F option.

which seems a bit counterintuitive if the user *did* specify one of those options along with --edit. I wonder if that message needs to be adjusted.

Show 11 quoted lines
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> @@ -452,6 +452,23 @@ test_expect_success \
> +get_tag_header annotated-tag-edit $commit commit $time >expect
> +echo "An edited message" >>expect
> +test_expect_success 'set up editor' '
> +       cat >editor <<-\EOF &&
> +       #!/bin/sh
> +       sed -e "s/A message/An edited message/g" <"$1" >"$1-"
> +       mv "$1-" "$1"
> +       EOF
> +       chmod 755 editor

If you use write_script() to create the fake editor, then it supplies the #!/bin/sh line for you and does the 'chmod', so you only need to supply the actual script payload. Also, other "editors" in this test file are named "fakeeditor", so perhaps follow suit.

    write_script fakeeditor <<-\EOF
        sed -e "s/A message/An edited message/g" <"$1" >"$1-"
        mv "$1-" "$1"
    EOF
Previous: Nicolas Morey-ChaisemartinNext: Nicolas Morey-Chaisemartin
Message 2 of 7 in “tag: add --edit option”
  1. tag: add --edit optionNicolas Morey-Chaisemartin, Feb 1, 2018
  2. Eric SunshineFeb 1, 2018
  3. Nicolas Morey-ChaisemartinFeb 1, 2018
  4. Nicolas Morey-ChaisemartinFeb 1, 2018
  5. Eric SunshineFeb 1, 2018
  6. Nicolas Morey-ChaisemartinFeb 1, 2018
  7. Ramsay JonesFeb 1, 2018

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.