threads / patch / 62267

patch, 3 partsdoc: merge-tree: improve the script example

Subject: [PATCH 0/3] doc: merge-tree: improve the script example

## tl;dr

27 messages between Oct 7, 2024 and Oct 10, 2024. Diffs are folded; open one to read it.

replies: 26people: 6as markdown or json

Kristoffer Haugsbakk· Oct 7, 2024, 11:10 UTC · lore
From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Kristoffer Haugsbakk (3):
  doc: merge-tree: provide a commit message
  doc: merge-tree: use lower-case variables
  doc: merge-tree: use || directly
 Documentation/git-merge-tree.txt | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

-- 2.46.1.641.g54e7913fcb6

Kristoffer Haugsbakk· Oct 7, 2024, 11:10 UTC · re: Kristoffer Haugsbakk · lore

[PATCH 1/3] doc: merge-tree: provide a commit message

From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
From: Kristoffer Haugsbakk <code@khaugsbakk.name>
Provide a commit message in the example command.

The command will hang since it is waiting for a commit message on stdin. Which is usable but not straightforward enough since this is example code.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
Notes (series):
    Unlike on some other manuals you probably won’t end up running these
    commands directly to test things out.  But you might end up copying and
    modifying it when playing around with the command.
 Documentation/git-merge-tree.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to Documentation/git-merge-tree.txt +1 −1
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 84cb2edf6d0..590cbf5df79 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -213,7 +213,7 @@ used as a part of a series of steps such as:
 
        NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
        test $? -eq 0 || die "There were conflicts..."
-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
+       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)
        git update-ref $BRANCH1 $NEWCOMMIT
 
 Note that when the exit status is non-zero, `NEWTREE` in this sequence
-- 
2.46.1.641.g54e7913fcb6
Kristoffer Haugsbakk· Oct 7, 2024, 12:02 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH 1/3] doc: merge-tree: provide a commit message

On Mon, Oct 7, 2024, at 13:10, Kristoffer Haugsbakk wrote:
> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
>
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>

I think these got double upped since I used `--from` in format-patch. Then I used send-email. format-patch warns against that:

  “ Note that this option is only useful if you are actually sending the
    emails and want to identify yourself as the sender, but
    retain the original author (and git am will correctly pick up
    the in-body header). Note also that git send-email already
    handles this transformation for you, and this option should
    not be used if you are feeding the result to git send-email.
So under the normal use I guess:

• You have someone else’s patches • send-email sees that you are not that person (because of your config) • It puts the From in the message body (it just works)

But that wasn’t the case for me since my ident is still the same as the author.

That went over my head before I sent.
-- 
Kristoffer Haugsbakk
Elijah Newren· Oct 7, 2024, 15:17 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH 1/3] doc: merge-tree: provide a commit message

On Mon, Oct 7, 2024 at 4:11 AM Kristoffer Haugsbakk <code@khaugsbakk.name> wrote:

Show 10 quoted lines
>
> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
>
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
> Provide a commit message in the example command.
>
> The command will hang since it is waiting for a commit message on
> stdin.  Which is usable but not straightforward enough since this is
> example code.
This is fine, but...
Show 22 quoted lines
>
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
>
> Notes (series):
>     Unlike on some other manuals you probably won’t end up running these
>     commands directly to test things out.  But you might end up copying and
>     modifying it when playing around with the command.
>
>  Documentation/git-merge-tree.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
> index 84cb2edf6d0..590cbf5df79 100644
> --- a/Documentation/git-merge-tree.txt
> +++ b/Documentation/git-merge-tree.txt
> @@ -213,7 +213,7 @@ used as a part of a series of steps such as:
>
>         NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
>         test $? -eq 0 || die "There were conflicts..."
> -       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
> +       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)

...perhaps this can be -F ${FILE_WITH_COMMIT_MESSAGE} ? I personally have a problem with writing example code that models horrible commit messages; I'd rather give them an example that hangs waiting on stdin than do that.

Show 5 quoted lines
>         git update-ref $BRANCH1 $NEWCOMMIT
>
>  Note that when the exit status is non-zero, `NEWTREE` in this sequence
> --
> 2.46.1.641.g54e7913fcb6
Kristoffer Haugsbakk· Oct 7, 2024, 15:23 UTC · re: Elijah Newren · lore

Re: [PATCH 1/3] doc: merge-tree: provide a commit message

On Mon, Oct 7, 2024, at 17:17, Elijah Newren wrote:
Show 9 quoted lines
>>         NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
>>         test $? -eq 0 || die "There were conflicts..."
>> -       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
>> +       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)
>
> ...perhaps this can be -F ${FILE_WITH_COMMIT_MESSAGE} ?  I personally
> have a problem with writing example code that models horrible commit
> messages; I'd rather give them an example that hangs waiting on stdin
> than do that.
Yes.  I’ll do that in the reroll.
Both this part and the uppercase variables.
Cheers
-- 
Kristoffer Haugsbakk
Kristoffer Haugsbakk· Oct 7, 2024, 11:10 UTC · re: Kristoffer Haugsbakk · lore

[PATCH 2/3] doc: merge-tree: use lower-case variables

From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
From: Kristoffer Haugsbakk <code@khaugsbakk.name>
This is easier to read.
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 Documentation/git-merge-tree.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Show changes to Documentation/git-merge-tree.txt +4 −4
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 590cbf5df79..10f8ac7f80a 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,12 +211,12 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
-       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
+       newtree=$(git merge-tree --write-tree $branch1 $branch2)
        test $? -eq 0 || die "There were conflicts..."
-       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)
-       git update-ref $BRANCH1 $NEWCOMMIT
+       newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
+       git update-ref $branch1 $newcommit
 
-Note that when the exit status is non-zero, `NEWTREE` in this sequence
+Note that when the exit status is non-zero, `newtree` in this sequence
 will contain a lot more output than just a tree.
 
 For conflicts, the output includes the same information that you'd get
-- 
2.46.1.641.g54e7913fcb6
Phillip Wood· Oct 7, 2024, 14:58 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH 2/3] doc: merge-tree: use lower-case variables

Hi Kristoffer
On 07/10/2024 12:10, Kristoffer Haugsbakk wrote:
Show 5 quoted lines
> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
> 
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
> 
> This is easier to read.

I think that is a matter of taste, one could argue that using uppercase variable names makes them stand out so the user can see which arguments are parameters more clearly.

Best Wishes
Phillip
Show 26 quoted lines
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
>   Documentation/git-merge-tree.txt | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
> index 590cbf5df79..10f8ac7f80a 100644
> --- a/Documentation/git-merge-tree.txt
> +++ b/Documentation/git-merge-tree.txt
> @@ -211,12 +211,12 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
>   linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
>   used as a part of a series of steps such as:
>   
> -       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
> +       newtree=$(git merge-tree --write-tree $branch1 $branch2)
>          test $? -eq 0 || die "There were conflicts..."
> -       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)
> -       git update-ref $BRANCH1 $NEWCOMMIT
> +       newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
> +       git update-ref $branch1 $newcommit
>   
> -Note that when the exit status is non-zero, `NEWTREE` in this sequence
> +Note that when the exit status is non-zero, `newtree` in this sequence
>   will contain a lot more output than just a tree.
>   
>   For conflicts, the output includes the same information that you'd get
Elijah Newren· Oct 7, 2024, 15:22 UTC · re: Phillip Wood · lore

Re: [PATCH 2/3] doc: merge-tree: use lower-case variables

On Mon, Oct 7, 2024 at 7:58 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 13 quoted lines
>
> Hi Kristoffer
>
> On 07/10/2024 12:10, Kristoffer Haugsbakk wrote:
> > From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
> >
> > From: Kristoffer Haugsbakk <code@khaugsbakk.name>
> >
> > This is easier to read.
>
> I think that is a matter of taste, one could argue that using uppercase
> variable names makes them stand out so the user can see which arguments
> are parameters more clearly.

Yeah, I wrote it as uppercase because I thought that was easier to read for the reasons Phillip gives. It's not a strong preference, but I do think the commit message needs a more detailed rationale or link to an agreed project coding style or something, otherwise the commit message may appear to be false to half the readers.

Kristoffer Haugsbakk· Oct 7, 2024, 11:10 UTC · re: Kristoffer Haugsbakk · lore

[PATCH 3/3] doc: merge-tree: use || directly

From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
From: Kristoffer Haugsbakk <code@khaugsbakk.name>

Use `||` directly since that is more straightforward than checking the last exit status.

Also use `echo` and `exit` since `die` is not defined.
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 Documentation/git-merge-tree.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Show changes to Documentation/git-merge-tree.txt +4 −2
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 10f8ac7f80a..46091da022d 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,8 +211,10 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
-       newtree=$(git merge-tree --write-tree $branch1 $branch2)
-       test $? -eq 0 || die "There were conflicts..."
+       newtree=$(git merge-tree --write-tree $branch1 $branch2) || {
+           echo "There were conflicts..." 1>&2
+           exit 1
+       }
        newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
        git update-ref $branch1 $newcommit
 
-- 
2.46.1.641.g54e7913fcb6
Elijah Newren· Oct 7, 2024, 15:24 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH 3/3] doc: merge-tree: use || directly

On Mon, Oct 7, 2024 at 4:11 AM Kristoffer Haugsbakk <code@khaugsbakk.name> wrote:

Show 9 quoted lines
>
> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
>
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
> Use `||` directly since that is more straightforward than checking the
> last exit status.
>
> Also use `echo` and `exit` since `die` is not defined.
Not defined where?  It's defined in my scripts...  ;-)
Just kidding; this is a good change.
Show 19 quoted lines
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
>  Documentation/git-merge-tree.txt | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
> index 10f8ac7f80a..46091da022d 100644
> --- a/Documentation/git-merge-tree.txt
> +++ b/Documentation/git-merge-tree.txt
> @@ -211,8 +211,10 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
>  linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
>  used as a part of a series of steps such as:
>
> -       newtree=$(git merge-tree --write-tree $branch1 $branch2)
> -       test $? -eq 0 || die "There were conflicts..."
> +       newtree=$(git merge-tree --write-tree $branch1 $branch2) || {
> +           echo "There were conflicts..." 1>&2
> +           exit 1
> +       }
Thanks.
Kristoffer Haugsbakk· Oct 7, 2024, 15:44 UTC · re: Elijah Newren · lore

Re: [PATCH 3/3] doc: merge-tree: use || directly

On Mon, Oct 7, 2024, at 17:24, Elijah Newren wrote:
Show 15 quoted lines
> On Mon, Oct 7, 2024 at 4:11 AM Kristoffer Haugsbakk
> <code@khaugsbakk.name> wrote:
>>
>> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
>>
>> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
>>
>> Use `||` directly since that is more straightforward than checking the
>> last exit status.
>>
>> Also use `echo` and `exit` since `die` is not defined.
>
> Not defined where?  It's defined in my scripts...  ;-)
>
> Just kidding; this is a good change.
:D
Thanks for taking a look! I’ll send the second version tomorrow.
-- 
Kristoffer Haugsbakk
Phillip Wood· Oct 7, 2024, 14:59 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH 0/3] doc: merge-tree: improve the script example

Hi Kristoffer

Thanks for working on this. Patches 1 and 3 look like clear improvements to me, I've left a comment on patch 2 as the improvement is less clear to me but I wouldn't object to it being merged.

Best Wishes
Phillip
On 07/10/2024 12:10, Kristoffer Haugsbakk wrote:
Show 14 quoted lines
> From: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
> 
> 
> Kristoffer Haugsbakk (3):
>    doc: merge-tree: provide a commit message
>    doc: merge-tree: use lower-case variables
>    doc: merge-tree: use || directly
> 
>   Documentation/git-merge-tree.txt | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
> 
> --
> 2.46.1.641.g54e7913fcb6
> 
Kristoffer Haugsbakk· Oct 7, 2024, 15:00 UTC · re: Phillip Wood · lore

Re: [PATCH 0/3] doc: merge-tree: improve the script example

On Mon, Oct 7, 2024, at 16:59, Phillip Wood wrote:
Show 9 quoted lines
> Hi Kristoffer
>
> Thanks for working on this. Patches 1 and 3 look like clear improvements 
> to me, I've left a comment on patch 2 as the improvement is less clear 
> to me but I wouldn't object to it being merged.
>
> Best Wishes
>
> Phillip
Thanks for taking a look!
-- 
Kristoffer Haugsbakk
Kristoffer Haugsbakk· Oct 8, 2024, 19:06 UTC · re: Kristoffer Haugsbakk · lore

[PATCH v2 0/2] doc: merge-tree: improve the script example

§ Changes since v1
Patches:

• v1 1: v2 1: use a file instead of `-mMerge` for the commit message • v1 2: dropped (lower-case variables) • v1 3: v2 2: no changes

Kristoffer Haugsbakk (2):
  doc: merge-tree: provide a commit message
  doc: merge-tree: use || directly
 Documentation/git-merge-tree.txt | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Interdiff against v1:
Show changes to Documentation/git-merge-tree.txt +5 −4
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 46091da022d..41dfb16476d 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,14 +211,15 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
-       newtree=$(git merge-tree --write-tree $branch1 $branch2) || {
+       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
            echo "There were conflicts..." 1>&2
            exit 1
        }
-       newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
-       git update-ref $branch1 $newcommit
+       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
+           -p $BRANCH1 -p $BRANCH2)
+       git update-ref $BRANCH1 $NEWCOMMIT
 
-Note that when the exit status is non-zero, `newtree` in this sequence
+Note that when the exit status is non-zero, `NEWTREE` in this sequence
 will contain a lot more output than just a tree.
 
 For conflicts, the output includes the same information that you'd get
Range-diff against v1:
1:  6b05526c327 < -:  ----------- doc: merge-tree: provide a commit message
2:  7d4deaee6c4 ! 1:  b1ca5cae768 doc: merge-tree: use lower-case variables
    @@ Metadata
     Author: Kristoffer Haugsbakk <code@khaugsbakk.name>
     
      ## Commit message ##
    -    doc: merge-tree: use lower-case variables
    +    doc: merge-tree: provide a commit message
     
    -    This is easier to read.
    +    Provide a commit message in the example command.
    +
    +    The command will hang since it is waiting for a commit message on
    +    stdin.  Which is usable but not straightforward enough since this is
    +    example code.
     
         Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
     
    +
    + ## Notes (series) ##
    +    Unlike on some other manuals you probably won’t end up running these
    +    commands directly to test things out.  But you might end up copying and
    +    modifying it when playing around with the command.
    +
      ## Documentation/git-merge-tree.txt ##
    -@@ Documentation/git-merge-tree.txt: linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
    - linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
    - used as a part of a series of steps such as:
    +@@ Documentation/git-merge-tree.txt: used as a part of a series of steps such as:
      
    --       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
    -+       newtree=$(git merge-tree --write-tree $branch1 $branch2)
    +        NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
             test $? -eq 0 || die "There were conflicts..."
    --       NEWCOMMIT=$(git commit-tree $NEWTREE -mMerge -p $BRANCH1 -p $BRANCH2)
    --       git update-ref $BRANCH1 $NEWCOMMIT
    -+       newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
    -+       git update-ref $branch1 $newcommit
    - 
    --Note that when the exit status is non-zero, `NEWTREE` in this sequence
    -+Note that when the exit status is non-zero, `newtree` in this sequence
    - will contain a lot more output than just a tree.
    +-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
    ++       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
    ++           -p $BRANCH1 -p $BRANCH2)
    +        git update-ref $BRANCH1 $NEWCOMMIT
      
    - For conflicts, the output includes the same information that you'd get
    + Note that when the exit status is non-zero, `NEWTREE` in this sequence
3:  1b60dc810e3 ! 2:  13e0f3bed5d doc: merge-tree: use || directly
    @@ Documentation/git-merge-tree.txt: linkgit:git-commit-tree[1], linkgit:git-write-
      linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
      used as a part of a series of steps such as:
      
    --       newtree=$(git merge-tree --write-tree $branch1 $branch2)
    +-       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
     -       test $? -eq 0 || die "There were conflicts..."
    -+       newtree=$(git merge-tree --write-tree $branch1 $branch2) || {
    ++       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
     +           echo "There were conflicts..." 1>&2
     +           exit 1
     +       }
    -        newcommit=$(git commit-tree $newtree -mMerge -p $branch1 -p $branch2)
    -        git update-ref $branch1 $newcommit
    - 
    +        NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
    +            -p $BRANCH1 -p $BRANCH2)
    +        git update-ref $BRANCH1 $NEWCOMMIT
-- 
2.46.1.641.g54e7913fcb6
Kristoffer Haugsbakk· Oct 8, 2024, 19:06 UTC · re: Kristoffer Haugsbakk · lore

[PATCH v2 1/2] doc: merge-tree: provide a commit message

Provide a commit message in the example command.

The command will hang since it is waiting for a commit message on stdin. Which is usable but not straightforward enough since this is example code.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
Notes (series):
    Unlike on some other manuals you probably won’t end up running these
    commands directly to test things out.  But you might end up copying and
    modifying it when playing around with the command.
 Documentation/git-merge-tree.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to Documentation/git-merge-tree.txt +2 −1
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 84cb2edf6d0..d1157f1398a 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -213,7 +213,8 @@ used as a part of a series of steps such as:
 
        NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
        test $? -eq 0 || die "There were conflicts..."
-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
+       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
+           -p $BRANCH1 -p $BRANCH2)
        git update-ref $BRANCH1 $NEWCOMMIT
 
 Note that when the exit status is non-zero, `NEWTREE` in this sequence
-- 
2.46.1.641.g54e7913fcb6
Junio C Hamano· Oct 8, 2024, 20:42 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v2 1/2] doc: merge-tree: provide a commit message

Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
Show 8 quoted lines
> Provide a commit message in the example command.
>
> The command will hang since it is waiting for a commit message on
> stdin.  Which is usable but not straightforward enough since this is
> example code.
>
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
Makes sense.
> -       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
> +       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
> +           -p $BRANCH1 -p $BRANCH2)
>         git update-ref $BRANCH1 $NEWCOMMIT

The shell should know, after seeing $FILE_WITH_COMMIT_MESSAGE and encountering the end of line, that you haven't completed telling what you started telling it. Do you need " \" at the end of the line?

I know that it was suggested to use a file with message, and I agree with the suggestion, but then I wonder if we want to be more complete and show that a file gets prepared in the example to avoid making readers wonder where $FILE_WITH_COMMIT_MESSAGE comes from?

E.g.,
        vi message.txt
        NEWCOMMIT=$(git comimt-tree $NEWTREE -F message.txt
                    -p $BRANCH1 -p $BRANCH2)
or something like that?
Other than that, looking good.
Thanks.
Kristoffer Haugsbakk· Oct 8, 2024, 20:44 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] doc: merge-tree: provide a commit message

On Tue, Oct 8, 2024, at 22:42, Junio C Hamano wrote:
> The shell should know, after seeing $FILE_WITH_COMMIT_MESSAGE and
> encountering the end of line, that you haven't completed telling
> what you started telling it.  Do you need " \" at the end of the
> line?
Heh, I’m not sure.  I’ll delete it if I don’t.
> I know that it was suggested to use a file with message, and I agree
> with the suggestion, but then I wonder if we want to be more
> complete and show that a file gets prepared in the example to avoid
> making readers wonder where $FILE_WITH_COMMIT_MESSAGE comes from?
Sure thing
Thanks :)
-- 
  Kristoffer Haugsbakk
  kristofferhaugsbakk@fastmail.com
Kristoffer Haugsbakk· Oct 9, 2024, 16:35 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] doc: merge-tree: provide a commit message

On Tue, Oct 8, 2024, at 22:42, Junio C Hamano wrote:
Show 22 quoted lines
> Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
>
>> Provide a commit message in the example command.
>>
>> The command will hang since it is waiting for a commit message on
>> stdin.  Which is usable but not straightforward enough since this is
>> example code.
>>
>> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
>> ---
>
> Makes sense.
>
>> -       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
>> +       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
>> +           -p $BRANCH1 -p $BRANCH2)
>>         git update-ref $BRANCH1 $NEWCOMMIT
>
> The shell should know, after seeing $FILE_WITH_COMMIT_MESSAGE and
> encountering the end of line, that you haven't completed telling
> what you started telling it.  Do you need " \" at the end of the
> line?
I tried that and got an error: `-p: not found`.
Show 12 quoted lines
> I know that it was suggested to use a file with message, and I agree
> with the suggestion, but then I wonder if we want to be more
> complete and show that a file gets prepared in the example to avoid
> making readers wonder where $FILE_WITH_COMMIT_MESSAGE comes from?
>
> E.g.,
>
>         vi message.txt
>         NEWCOMMIT=$(git comimt-tree $NEWTREE -F message.txt
>                     -p $BRANCH1 -p $BRANCH2)
>
> or something like that?
I’ll do that.

-- Kristoffer but any Christopher-variation is fine

Junio C Hamano· Oct 9, 2024, 17:38 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v2 1/2] doc: merge-tree: provide a commit message

"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:
Show 10 quoted lines
>>> +       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
>>> +           -p $BRANCH1 -p $BRANCH2)
>>>         git update-ref $BRANCH1 $NEWCOMMIT
>>
>> The shell should know, after seeing $FILE_WITH_COMMIT_MESSAGE and
>> encountering the end of line, that you haven't completed telling
>> what you started telling it.  Do you need " \" at the end of the
>> line?
>
> I tried that and got an error: `-p: not found`.

Thanks for trying. Sorry, but I think I got confused by trying it with two "echo" (one per line). The newline still acts as a inter-command separator.

Show 9 quoted lines
>> E.g.,
>>
>>         vi message.txt
>>         NEWCOMMIT=$(git comimt-tree $NEWTREE -F message.txt
>>                     -p $BRANCH1 -p $BRANCH2)
>>
>> or something like that?
>
> I’ll do that.
Andreas Schwab· Oct 9, 2024, 16:58 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] doc: merge-tree: provide a commit message

On Okt 08 2024, Junio C Hamano wrote:
Show 9 quoted lines
>> -       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
>> +       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
>> +           -p $BRANCH1 -p $BRANCH2)
>>         git update-ref $BRANCH1 $NEWCOMMIT
>
> The shell should know, after seeing $FILE_WITH_COMMIT_MESSAGE and
> encountering the end of line, that you haven't completed telling
> what you started telling it.  Do you need " \" at the end of the
> line?

The contents of $(...) is a (multiline) shell script, with the same whitespace and newline rules as a regular script.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Kristoffer Haugsbakk· Oct 8, 2024, 19:06 UTC · re: Kristoffer Haugsbakk · lore

[PATCH v2 2/2] doc: merge-tree: use || directly

Use `||` directly since that is more straightforward than checking the last exit status.

Also use `echo` and `exit` since `die` is not defined.
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 Documentation/git-merge-tree.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Show changes to Documentation/git-merge-tree.txt +4 −2
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index d1157f1398a..41dfb16476d 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,8 +211,10 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
-       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
-       test $? -eq 0 || die "There were conflicts..."
+       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
+           echo "There were conflicts..." 1>&2
+           exit 1
+       }
        NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
            -p $BRANCH1 -p $BRANCH2)
        git update-ref $BRANCH1 $NEWCOMMIT
-- 
2.46.1.641.g54e7913fcb6
Junio C Hamano· Oct 8, 2024, 20:44 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v2 2/2] doc: merge-tree: use || directly

Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
Show 6 quoted lines
> -       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
> -       test $? -eq 0 || die "There were conflicts..."
> +       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
> +           echo "There were conflicts..." 1>&2
> +           exit 1
> +       }

Makes sense. Was there a particular reason why these two patches had to be done in two separate steps?

Looking good otherwise.  Thanks.
Kristoffer Haugsbakk· Oct 8, 2024, 20:48 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] doc: merge-tree: use || directly

On Tue, Oct 8, 2024, at 22:44, Junio C Hamano wrote:
Show 13 quoted lines
> Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
>
>> -       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
>> -       test $? -eq 0 || die "There were conflicts..."
>> +       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
>> +           echo "There were conflicts..." 1>&2
>> +           exit 1
>> +       }
>
> Makes sense.  Was there a particular reason why these two patches
> had to be done in two separate steps?
>
> Looking good otherwise.  Thanks.
Just my usual do-one-thing-per-commit.

In this case a simple Also-paragraph can connect the two. So squashing them is fine too.

-- 
  Kristoffer Haugsbakk
  kristofferhaugsbakk@fastmail.com
Kristoffer Haugsbakk· Oct 9, 2024, 16:53 UTC · re: Kristoffer Haugsbakk · lore

[PATCH v3 0/1] doc: merge-tree: improve the script example

§ Changes since v2
• Squash into one patch
• Use `vi message.txt` before `git commit-tree`
• Also declare the branches
  • Fully qualified for `BRANCH1` since it is passed to
    git-update-ref(1)
Kristoffer Haugsbakk (1):
  doc: merge-tree: improve example script
 Documentation/git-merge-tree.txt | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Interdiff against v2:
Show changes to Documentation/git-merge-tree.txt +4 −1
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 41dfb16476d..0b6a8a19b1f 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,11 +211,14 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
+       vi message.txt
+       BRANCH1=refs/heads/test
+       BRANCH2=main
        NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
            echo "There were conflicts..." 1>&2
            exit 1
        }
-       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
+       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
            -p $BRANCH1 -p $BRANCH2)
        git update-ref $BRANCH1 $NEWCOMMIT
 
Range-diff against v2:
1:  b1ca5cae768 < -:  ----------- doc: merge-tree: provide a commit message
2:  13e0f3bed5d ! 1:  c7e0d76e71e doc: merge-tree: use || directly
    @@ Metadata
     Author: Kristoffer Haugsbakk <code@khaugsbakk.name>
     
      ## Commit message ##
    -    doc: merge-tree: use || directly
    +    doc: merge-tree: improve example script
     
    -    Use `||` directly since that is more straightforward than checking the
    -    last exit status.
    +    • Provide a commit message in the example command.
     
    -    Also use `echo` and `exit` since `die` is not defined.
    +      The command will hang since it is waiting for a commit message on
    +      stdin.  Which is usable but not straightforward enough since this is
    +      example code.
    +    • Use `||` directly since that is more straightforward than checking the
    +      last exit status.
    +
    +      Also use `echo` and `exit` since `die` is not defined.
    +    • Expose variable declarations.
     
         Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
     
    @@ Documentation/git-merge-tree.txt: linkgit:git-commit-tree[1], linkgit:git-write-
      
     -       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
     -       test $? -eq 0 || die "There were conflicts..."
    +-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
    ++       vi message.txt
    ++       BRANCH1=refs/heads/test
    ++       BRANCH2=main
     +       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
     +           echo "There were conflicts..." 1>&2
     +           exit 1
     +       }
    -        NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
    -            -p $BRANCH1 -p $BRANCH2)
    ++       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
    ++           -p $BRANCH1 -p $BRANCH2)
             git update-ref $BRANCH1 $NEWCOMMIT
    + 
    + Note that when the exit status is non-zero, `NEWTREE` in this sequence
-- 
2.46.1.641.g54e7913fcb6
Kristoffer Haugsbakk· Oct 9, 2024, 16:53 UTC · re: Kristoffer Haugsbakk · lore

[PATCH v3 1/1] doc: merge-tree: improve example script

• Provide a commit message in the example command.
  The command will hang since it is waiting for a commit message on
  stdin.  Which is usable but not straightforward enough since this is
  example code.
• Use `||` directly since that is more straightforward than checking the
  last exit status.
  Also use `echo` and `exit` since `die` is not defined.
• Expose variable declarations.
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 Documentation/git-merge-tree.txt | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Show changes to Documentation/git-merge-tree.txt +9 −3
diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
index 84cb2edf6d0..0b6a8a19b1f 100644
--- a/Documentation/git-merge-tree.txt
+++ b/Documentation/git-merge-tree.txt
@@ -211,9 +211,15 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
 linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
 used as a part of a series of steps such as:
 
-       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
-       test $? -eq 0 || die "There were conflicts..."
-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
+       vi message.txt
+       BRANCH1=refs/heads/test
+       BRANCH2=main
+       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
+           echo "There were conflicts..." 1>&2
+           exit 1
+       }
+       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
+           -p $BRANCH1 -p $BRANCH2)
        git update-ref $BRANCH1 $NEWCOMMIT
 
 Note that when the exit status is non-zero, `NEWTREE` in this sequence
-- 
2.46.1.641.g54e7913fcb6
Elijah Newren· Oct 9, 2024, 20:50 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v3 0/1] doc: merge-tree: improve the script example

On Wed, Oct 9, 2024 at 9:54 AM Kristoffer Haugsbakk <code@khaugsbakk.name> wrote:

Show 83 quoted lines
>
> § Changes since v2
>
> • Squash into one patch
> • Use `vi message.txt` before `git commit-tree`
> • Also declare the branches
>   • Fully qualified for `BRANCH1` since it is passed to
>     git-update-ref(1)
>
> Kristoffer Haugsbakk (1):
>   doc: merge-tree: improve example script
>
>  Documentation/git-merge-tree.txt | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> Interdiff against v2:
> diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt
> index 41dfb16476d..0b6a8a19b1f 100644
> --- a/Documentation/git-merge-tree.txt
> +++ b/Documentation/git-merge-tree.txt
> @@ -211,11 +211,14 @@ linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
>  linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
>  used as a part of a series of steps such as:
>
> +       vi message.txt
> +       BRANCH1=refs/heads/test
> +       BRANCH2=main
>         NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
>             echo "There were conflicts..." 1>&2
>             exit 1
>         }
> -       NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
> +       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
>             -p $BRANCH1 -p $BRANCH2)
>         git update-ref $BRANCH1 $NEWCOMMIT
>
> Range-diff against v2:
> 1:  b1ca5cae768 < -:  ----------- doc: merge-tree: provide a commit message
> 2:  13e0f3bed5d ! 1:  c7e0d76e71e doc: merge-tree: use || directly
>     @@ Metadata
>      Author: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
>       ## Commit message ##
>     -    doc: merge-tree: use || directly
>     +    doc: merge-tree: improve example script
>
>     -    Use `||` directly since that is more straightforward than checking the
>     -    last exit status.
>     +    • Provide a commit message in the example command.
>
>     -    Also use `echo` and `exit` since `die` is not defined.
>     +      The command will hang since it is waiting for a commit message on
>     +      stdin.  Which is usable but not straightforward enough since this is
>     +      example code.
>     +    • Use `||` directly since that is more straightforward than checking the
>     +      last exit status.
>     +
>     +      Also use `echo` and `exit` since `die` is not defined.
>     +    • Expose variable declarations.
>
>          Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
>     @@ Documentation/git-merge-tree.txt: linkgit:git-commit-tree[1], linkgit:git-write-
>
>      -       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
>      -       test $? -eq 0 || die "There were conflicts..."
>     +-       NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
>     ++       vi message.txt
>     ++       BRANCH1=refs/heads/test
>     ++       BRANCH2=main
>      +       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
>      +           echo "There were conflicts..." 1>&2
>      +           exit 1
>      +       }
>     -        NEWCOMMIT=$(git commit-tree $NEWTREE -F $FILE_WITH_COMMIT_MESSAGE \
>     -            -p $BRANCH1 -p $BRANCH2)
>     ++       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
>     ++           -p $BRANCH1 -p $BRANCH2)
>              git update-ref $BRANCH1 $NEWCOMMIT
>     +
>     + Note that when the exit status is non-zero, `NEWTREE` in this sequence
> --
> 2.46.1.641.g54e7913fcb6
This round looks good to me; thanks.
Junio C Hamano· Oct 10, 2024, 00:01 UTC · re: Elijah Newren · lore

Re: [PATCH v3 0/1] doc: merge-tree: improve the script example

Elijah Newren <newren@gmail.com> writes:
Show 6 quoted lines
> On Wed, Oct 9, 2024 at 9:54 AM Kristoffer Haugsbakk
> <code@khaugsbakk.name> wrote:
>> ...
>> 2.46.1.641.g54e7913fcb6
>
> This round looks good to me; thanks.
Thanks.

← back to recent threads