diff options
author | wxiaoguang | 2023-02-21 14:12:57 +0800 |
---|---|---|
committer | GitHub | 2023-02-21 14:12:57 +0800 |
commit | dc9cebdf45d3594058727a5c8a5f20af098c5e7a (patch) | |
tree | 3b1159ee7cf0de7ac94b480e835ff3c27fd9266b /modules | |
parent | e3cffa70f9f731436ab005e4bb10f57166ffc6d5 (diff) |
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>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/commit.go | 2 | ||||
-rw-r--r-- | modules/repository/init.go | 5 |
2 files changed, 3 insertions, 4 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go index 1f6289ed0..4a55645d3 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -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. diff --git a/modules/repository/init.go b/modules/repository/init.go index 5705fe5b9..771b68a49 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -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 { |