]> source.dussan.org Git - gitea.git/commitdiff
Use `--message=%s` for git commit message (#23028)
authorwxiaoguang <wxiaoguang@gmail.com>
Tue, 21 Feb 2023 06:12:57 +0000 (14:12 +0800)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2023 06:12:57 +0000 (14:12 +0800)
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>
modules/git/commit.go
modules/repository/init.go
services/pull/merge.go

index 1f6289ed0222402954c217c9e5c7a3d7cc8ba8dd..4a55645d303460193ef6c23e166705a27d784c4e 100644 (file)
@@ -131,7 +131,7 @@ func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChan
        if opts.Author != nil {
                cmd.AddOptionFormat("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)
        }
-       cmd.AddOptionValues("-m", opts.Message)
+       cmd.AddOptionFormat("--message=%s", opts.Message)
 
        _, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath})
        // No stderr but exit status 1 means nothing to commit.
index 5705fe5b998e40ef89658300abb9552c90e765ff..771b68a4916f8e255c7ce4fc9297b5be466675fa 100644 (file)
@@ -316,9 +316,8 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
                return fmt.Errorf("git add --all: %w", err)
        }
 
-       cmd := git.NewCommand(ctx, "commit").
-               AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
-               AddOptionValues("-m", "Initial commit")
+       cmd := git.NewCommand(ctx, "commit", "--message=Initial commit").
+               AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email)
 
        sign, keyID, signer, _ := asymkey_service.SignInitialCommit(ctx, tmpPath, u)
        if sign {
index 3ac67d91b72f188ae16c8cbd6bff3c95c71a2c57..ad428427cc187c56b36f6b41d0afab515ed5ae50 100644 (file)
@@ -533,7 +533,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
                if err := git.NewCommand(ctx, "commit").
                        AddArguments(signArgs...).
                        AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
-                       AddOptionValues("-m", message).
+                       AddOptionFormat("--message=%s", message).
                        Run(&git.RunOpts{
                                Env:    env,
                                Dir:    tmpBasePath,
@@ -641,7 +641,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
 
 func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, message string, signArgs git.TrustedCmdArgs, tmpBasePath string, env []string) error {
        var outbuf, errbuf strings.Builder
-       if err := git.NewCommand(ctx, "commit").AddArguments(signArgs...).AddOptionValues("-m", message).
+       if err := git.NewCommand(ctx, "commit").AddArguments(signArgs...).AddOptionFormat("--message=%s", message).
                Run(&git.RunOpts{
                        Env:    env,
                        Dir:    tmpBasePath,