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

Re: [PATCH v5] branch: introduce --show-current display option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 25, 2018, 19:30 UTC
Message-ID
<CAPig+cRVdogY8VLXcftbY=n9tQ9wDo4YrnrdU6+pZ3ch6uhZGA@mail.gmail.com>
In-Reply-To
<20181025190421.15022-1-daniels@umanovskis.se>

On Thu, Oct 25, 2018 at 3:04 PM Daniels Umanovskis <daniels@umanovskis.se> wrote:

Show 19 quoted lines
> When called with --show-current, git branch will print the current
> branch name and terminate. Only the actual name gets printed,
> without refs/heads. In detached HEAD state, nothing is output.
>
> Signed-off-by: Daniels Umanovskis <daniels@umanovskis.se>
> ---
> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
> @@ -100,6 +100,50 @@ test_expect_success 'git branch -v pattern does not show branch summaries' '
> +test_expect_success 'git branch `--show-current` works properly when tag exists' '
> +       cat >expect <<-\EOF &&
> +       branch-and-tag-name
> +       EOF
> +       test_when_finished "
> +               git checkout branch-one
> +               git branch -D branch-and-tag-name
> +       " &&
> +       git checkout -b branch-and-tag-name &&
> +       test_when_finished "git tag -d branch-and-tag-name" &&
> +       git tag branch-and-tag-name &&

If git-tag crashes before actually creating the new tag, then "git tag -d", passed to test_when_finished(), will error out too, which is probably undesirable since "cleanup code" isn't expected to error out. You could fix it this way:

    test_when_finished "git tag -d branch-and-tag-name || :" &&
    git tag branch-and-tag-name &&
or, even better, just swap the two lines:
    git tag branch-and-tag-name &&
    test_when_finished "git tag -d branch-and-tag-name" &&

However, do you even need to clean up the tag? Are there tests following this one which expect a certain set of tags and fail if this new one is present? If not, a simpler approach might be just to leave the tag alone (and the branch too if that doesn't need to be cleaned up).

> +       git branch --show-current >actual &&
> +       test_cmp expect actual
> +'
Previous: Daniels UmanovskisNext: Junio C Hamano
Message 2 of 8 in “branch: introduce --show-current display option”
  1. branch: introduce --show-current display optionDaniels Umanovskis, Oct 25, 2018
  2. Eric SunshineOct 25, 2018
  3. Junio C HamanoOct 26, 2018
  4. Jeff KingNov 1, 2018
  5. Junio C HamanoOct 26, 2018
  6. branch: make --show-current use already resolved HEADRafael Ascensão, Nov 7, 2018
  7. Junio C HamanoNov 8, 2018
  8. Rafael AscensãoNov 8, 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.