Skip to content

Commit dc9cebd

Browse files
wxiaoguanglunny
andauthored
Use --message=%s for git commit message (#23028)
Close #23027 `git commit` message option _only_ supports 4 formats (well, only ....): * `"commit", "-m", msg` * `"commit", "-m{msg}"` (no space) * `"commit", "--message", msg` * `"commit", "--message={msg}"` The long format with `=` is the best choice, and it's documented in `man git-commit`: `-m <msg>, --message=<msg> ...` ps: I would suggest always use long format option for git command, as much as possible. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent e3cffa7 commit dc9cebd

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

modules/git/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChan
131131
if opts.Author != nil {
132132
cmd.AddOptionFormat("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)
133133
}
134-
cmd.AddOptionValues("-m", opts.Message)
134+
cmd.AddOptionFormat("--message=%s", opts.Message)
135135

136136
_, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath})
137137
// No stderr but exit status 1 means nothing to commit.

modules/repository/init.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
316316
return fmt.Errorf("git add --all: %w", err)
317317
}
318318

319-
cmd := git.NewCommand(ctx, "commit").
320-
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
321-
AddOptionValues("-m", "Initial commit")
319+
cmd := git.NewCommand(ctx, "commit", "--message=Initial commit").
320+
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email)
322321

323322
sign, keyID, signer, _ := asymkey_service.SignInitialCommit(ctx, tmpPath, u)
324323
if sign {

services/pull/merge.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
533533
if err := git.NewCommand(ctx, "commit").
534534
AddArguments(signArgs...).
535535
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
536-
AddOptionValues("-m", message).
536+
AddOptionFormat("--message=%s", message).
537537
Run(&git.RunOpts{
538538
Env: env,
539539
Dir: tmpBasePath,
@@ -641,7 +641,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
641641

642642
func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, message string, signArgs git.TrustedCmdArgs, tmpBasePath string, env []string) error {
643643
var outbuf, errbuf strings.Builder
644-
if err := git.NewCommand(ctx, "commit").AddArguments(signArgs...).AddOptionValues("-m", message).
644+
if err := git.NewCommand(ctx, "commit").AddArguments(signArgs...).AddOptionFormat("--message=%s", message).
645645
Run(&git.RunOpts{
646646
Env: env,
647647
Dir: tmpBasePath,

0 commit comments

Comments
 (0)