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

Re: [PATCH v2] worktree: add --quiet option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 16, 2018, 08:43 UTC
Message-ID
<CAPig+cTSZNtKUXLoR6gqvWT3bD-JgWOF38ZD7i+OocRs4p=GMA@mail.gmail.com>
In-Reply-To
<20180815205630.32876-1-gitter.spiros@gmail.com>
On Wed, Aug 15, 2018 at 4:56 PM Elia Pinto <gitter.spiros@gmail.com> wrote:
Show 5 quoted lines
> Add the '--quiet' option to git worktree,
> as for the other git commands. 'add' is the
> only command affected by it since all other
> commands, except 'list', are currently
> silent by default.
Nit: wrap the commit message at around 70 columns rather than 45 or so.
Show 10 quoted lines
> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -303,9 +304,13 @@ static int add_worktree(const char *path, const char *refname,
> +       else {
>                 argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",
>                                  symref.buf, NULL);
> +               if (opts->quiet)
> +                       argv_array_push(&cp.args, "--quiet");
> +       }

This constructs the command as "git symbolic-ref HEAD <ref> --quiet". Although that's not wrong per-se, it does perhaps set an undesirable precedent. A more standard construction would be:

    argv_array_push(..., "symbolic-ref");
    if (opts->quiet)
        argv_array_push(..., "--quiet");
    argv_array_pushl(..., "HEAD", symref.buf, NULL);

I used "pushl" on the last one to indicate the semantic relationship between those two arguments.

> +
Nit: the above code is directly related to the code just below, so the
new blank line you add here somewhat (undesirably) divorces the pieces
of code from each other
Show 7 quoted lines
>         cp.env = child_env.argv;
>         ret = run_command(&cp);
>         if (ret)
> @@ -315,6 +320,8 @@ static int add_worktree(const char *path, const char *refname,
>                 argv_array_pushl(&cp.args, "reset", "--hard", NULL);
> +               if (opts->quiet)
> +                       argv_array_push(&cp.args, "--quiet");
I could also see this one re-written as:
    argv_array_push(...,"reset");
    argv_array_push(...,"--hard");
    if (opts->quiet)
        argv_array_push(...,"--quiet");
now that the command invocation has added another option.
Not at all worth a re-roll.
Show 6 quoted lines
> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
> @@ -252,6 +252,11 @@ test_expect_success 'add -B' '
> +test_expect_success 'add --quiet' '
> +       git worktree add --quiet ../foo master >expected 2>&1 &&
> +       test_must_be_empty expected
> +'

This test is going to create the new worktree directly in Git's t/ directory due to "../foo". Please don't do that. Use a name without the leading "../".

Also, you should make sure that the worktree doesn't already exist (wasn't created by an earlier test), otherwise the "git worktree add" command will fail. So, either choose a distinct worktree name or use "test_might_fail git worktree remove -f <worktree>" before the "git worktree add" command.

Previous: Martin ÅgrenNext: Junio C Hamano
Message 6 of 8 in “worktree: add --quiet option”
  1. worktree: add --quiet optionElia Pinto, Aug 15, 2018
  2. Thomas GummererAug 15, 2018
  3. Martin ÅgrenAug 16, 2018
  4. Eric SunshineAug 16, 2018
  5. Martin ÅgrenAug 16, 2018
  6. Eric SunshineAug 16, 2018
  7. Junio C HamanoAug 16, 2018
  8. Junio C HamanoAug 16, 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.