Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Conversation

peterguy
Copy link
Contributor

@peterguy peterguy commented Aug 9, 2023

Commit messages for batch changes can be arbitrary strings, so passing them inline to the command arguments using -m is prone to problems and edge cases.
Solving those problems and edge cases is non-optimal, so pivot to using a different way to specify commit messages: from a file (stdin in this case). This allows commit messages to contain arbitrary characters without needing to worry about escaping or edge cases.

Test plan

in a batch spec, use a commit message that contains newlines (use message: | followed by the message on the next line, indented more than message). Check the commit message on the code host after the patch has been published.

You can include other characters in the commit message (one edge case we've seen is beginning the commit message with a dash) to ensure they are also handled correctly.

Commit messages for batch changes can be arbitrary strings,
so passing them inline to the command arguments using `-m`
is prone to problems and edge cases.
Solving those problems and edge cases is non-optimal,
so pivot to using a different way to specify commit messages:
from a file (stdin in this case). This allows commit messages to contain
arbitrary characters without needing to worry about escaping or edge cases.
@peterguy peterguy added the team/code-search Issues owned by the code search team label Aug 9, 2023
@peterguy peterguy requested a review from a team August 9, 2023 05:56
@peterguy peterguy self-assigned this Aug 9, 2023
@cla-bot cla-bot bot added the cla-signed label Aug 9, 2023
@peterguy peterguy linked an issue Aug 9, 2023 that may be closed by this pull request
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Aug 9, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff 4ffba4e...06f2163.

Notify File(s)
@indradhanush cmd/gitserver/server/patch.go
@sashaostrikov cmd/gitserver/server/patch.go

Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

return false
}
if strings.HasPrefix(arg, "-") {
fmt.Printf("EVALUATING ARGUMENT %d: %s\n", i, arg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Printf("EVALUATING ARGUMENT %d: %s\n", i, arg)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t feel super strongly about the other comments, but I think we should address this one in a follow up 🙂

}

// I hate state machines, but I hate them less than complicated multi-argument checking
checkFileInput := false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get a test for this new added behavior?

// NOTE: join messages with a blank line in between ("\n\n")
// because the previous behavior was to use multiple -m arguments,
// which concatenate with a blank line in between.
// Gerrit is the only code host that usees multiple messages at the moment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Gerrit is the only code host that usees multiple messages at the moment
// Gerrit is the only code host that uses multiple messages at the moment

@peterguy peterguy merged commit d1202d8 into main Aug 9, 2023
@peterguy peterguy deleted the peterguy/fix-batch-change-commit-message branch August 9, 2023 17:00
peterguy added a commit that referenced this pull request Aug 9, 2023
Implemented suggestions to remove debug code, add test and fix typo
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

The backport to 5.1 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.1 5.1
# Navigate to the new working tree
cd .worktrees/backport-5.1
# Create a new branch
git switch --create backport-55657-to-5.1
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 d1202d873566cf93c74833d5574340997a818c06
# Push it to GitHub
git push --set-upstream origin backport-55657-to-5.1
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.1

Then, create a pull request where the base branch is 5.1 and the compare/head branch is backport-55657-to-5.1.

@github-actions github-actions bot added backports failed-backport-to-5.1 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases labels Aug 9, 2023
peterguy added a commit that referenced this pull request Aug 9, 2023
Commit messages for batch changes can be arbitrary strings, so passing
them inline to the command arguments using `-m` is prone to problems and
edge cases.
Solving those problems and edge cases is non-optimal, so pivot to using
a different way to specify commit messages: from a file (stdin in this
case). This allows commit messages to contain arbitrary characters
without needing to worry about escaping or edge cases.

in a batch spec, use a commit message that contains newlines (use
`message: |` followed by the message on the next line, indented more
than `message`). Check the commit message on the code host after the
patch has been published.

You can include other characters in the commit message (one edge case
we've seen is beginning the commit message with a dash) to ensure they
are also handled correctly.

(cherry picked from commit d1202d8)
peterguy added a commit that referenced this pull request Aug 9, 2023
Implemented suggestions to remove debug code, add test and fix typo



## Test plan

gitdomain test will include a test of the newly-allowed `git commit`
arguments
davejrt pushed a commit that referenced this pull request Aug 9, 2023
Commit messages for batch changes can be arbitrary strings, so passing
them inline to the command arguments using `-m` is prone to problems and
edge cases.
Solving those problems and edge cases is non-optimal, so pivot to using
a different way to specify commit messages: from a file (stdin in this
case). This allows commit messages to contain arbitrary characters
without needing to worry about escaping or edge cases.



## Test plan
in a batch spec, use a commit message that contains newlines (use
`message: |` followed by the message on the next line, indented more
than `message`). Check the commit message on the code host after the
patch has been published.

You can include other characters in the commit message (one edge case
we've seen is beginning the commit message with a dash) to ensure they
are also handled correctly.
davejrt pushed a commit that referenced this pull request Aug 9, 2023
Implemented suggestions to remove debug code, add test and fix typo



## Test plan

gitdomain test will include a test of the newly-allowed `git commit`
arguments
peterguy added a commit that referenced this pull request Aug 24, 2023
jdpleiness pushed a commit that referenced this pull request Aug 24, 2023
@BolajiOlajide BolajiOlajide removed the release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases label Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed team/code-search Issues owned by the code search team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commit message double-quoted
4 participants