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

Re: [PATCH v2] contrib/subtree: fix split with squashed subtrees

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 10, 2025, 02:02 UTC
Message-ID
<xmqqbjnjt67y.fsf@gitster.g>
In-Reply-To
<8d341a51-2135-4c62-9df1-5be351e73275@howdoi.land>
Colin Stagner <ask+git@howdoi.land> writes:
Show 10 quoted lines
>>> -    if test -n "$(git log -1 --grep="git-subtree-dir:" $rev)"
>>> +    if test -n "${subtree_dir:-}" &&
>>> +        test -z "${have_mainline:-}" &&
>>> +        test "${subtree_dir}" != "$arg_prefix"
>> What's the idea behind using "${var:-}" rather than "{var}"?
>
> I write a lot of shell scripts that run "set -u" (aka "set -o
> nounset"), so I do this a lot when testing for empty vars. In this
> case, it's not actually necessary since `have_mainline` is explicitly
> defined above. And we don't run `set -u` anyway.

Besides, "if test -n ${subtree_dir-}" without colon would be the more proper way for those who care about "set -u", wouldn't it? It is not that you want to substitute with an empty string that comes between that "-" and "}" when subtree_dir is unset or set to empty. You are preparing for the case where the variable is truly not set, and the variable being set to an empty string is not something you are worried about. THe same for ${have_mainline:-}.

>> If you use "git switch --orphan" that clears the worktree for you
>
> Very useful. I'll start using it in v3.
Excellent suggestion.
Previous: Colin StagnerNext: Colin Stagner
Message 10 of 15 in “contrib/subtree: fix split with squashed subtrees”
  1. contrib/subtree: fix split with squashed subtreesColin Stagner, Aug 24, 2025
  2. Phillip WoodSep 1, 2025
  3. Colin StagnerSep 1, 2025
  4. Phillip WoodSep 2, 2025
  5. Phillip WoodSep 2, 2025
  6. Colin StagnerSep 4, 2025
  7. contrib/subtree: fix split with squashed subtreesColin Stagner, Sep 5, 2025
  8. Phillip WoodSep 8, 2025
  9. Colin StagnerSep 10, 2025
  10. Junio C HamanoSep 10, 2025
  11. Colin StagnerSep 10, 2025
  12. Junio C HamanoSep 10, 2025
  13. contrib/subtree: fix split with squashed subtreesColin Stagner, Sep 10, 2025
  14. Phillip WoodSep 10, 2025
  15. Junio C HamanoSep 11, 2025

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.