mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -131,7 +131,7 @@ func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChan | |||||||
| 	if opts.Author != nil { | 	if opts.Author != nil { | ||||||
| 		cmd.AddOptionFormat("--author='%s <%s>'", opts.Author.Name, opts.Author.Email) | 		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}) | 	_, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}) | ||||||
| 	// No stderr but exit status 1 means nothing to commit. | 	// No stderr but exit status 1 means nothing to commit. | ||||||
|   | |||||||
| @@ -316,9 +316,8 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi | |||||||
| 		return fmt.Errorf("git add --all: %w", err) | 		return fmt.Errorf("git add --all: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	cmd := git.NewCommand(ctx, "commit"). | 	cmd := git.NewCommand(ctx, "commit", "--message=Initial commit"). | ||||||
| 		AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email). | 		AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email) | ||||||
| 		AddOptionValues("-m", "Initial commit") |  | ||||||
|  |  | ||||||
| 	sign, keyID, signer, _ := asymkey_service.SignInitialCommit(ctx, tmpPath, u) | 	sign, keyID, signer, _ := asymkey_service.SignInitialCommit(ctx, tmpPath, u) | ||||||
| 	if sign { | 	if sign { | ||||||
|   | |||||||
| @@ -533,7 +533,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode | |||||||
| 		if err := git.NewCommand(ctx, "commit"). | 		if err := git.NewCommand(ctx, "commit"). | ||||||
| 			AddArguments(signArgs...). | 			AddArguments(signArgs...). | ||||||
| 			AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email). | 			AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email). | ||||||
| 			AddOptionValues("-m", message). | 			AddOptionFormat("--message=%s", message). | ||||||
| 			Run(&git.RunOpts{ | 			Run(&git.RunOpts{ | ||||||
| 				Env:    env, | 				Env:    env, | ||||||
| 				Dir:    tmpBasePath, | 				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 { | func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, message string, signArgs git.TrustedCmdArgs, tmpBasePath string, env []string) error { | ||||||
| 	var outbuf, errbuf strings.Builder | 	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{ | 		Run(&git.RunOpts{ | ||||||
| 			Env:    env, | 			Env:    env, | ||||||
| 			Dir:    tmpBasePath, | 			Dir:    tmpBasePath, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user