Skip to content

Commit 2ee1456

Browse files
committed
fix
1 parent cfb0709 commit 2ee1456

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

CHANGELOG-archived.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ This changelog (archived) contains changes for old releases.
21752175
* Don't send notification on pending reviews (#8943)
21762176
* Fix Notify Create Ref Error on tag creation (#8936)
21772177
* Convert EOL to UNIX-style to render MD properly (#8925)
2178-
* Migrate temp_repo.go to use gitcmd.NewCommand (#8918)
2178+
* Migrate temp_repo.go to use git.NewCommand (#8918)
21792179
* Fix issue with user.fullname (#8902)
21802180
* Add Close() method to gogitRepository (#8901)
21812181
* Enable punctuations ending mentions (#8889)

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4170,7 +4170,7 @@ Key highlights of this release encompass significant changes categorized under `
41704170
* Add number in queue status to monitor page (#18712)
41714171
* Change git.cmd to RunWithContext (#18693)
41724172
* Refactor i18n, use Locale to provide i18n/translation related functions (#18648)
4173-
* Delete old gitcmd.NewCommand() and use it as gitcmd.NewCommandContext() (#18552)
4173+
* Delete old git.NewCommand() and use it as git.NewCommandContext() (#18552)
41744174
* Move organization related structs into sub package (#18518)
41754175
* Warn at startup if the provided `SCRIPT_TYPE` is not on the PATH (#18467)
41764176
* Use `CryptoRandomBytes` instead of `CryptoRandomString` (#18439)

modules/git/config.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ package git
55

66
import (
77
"context"
8-
"errors"
98
"fmt"
109
"os"
11-
"os/exec"
1210
"regexp"
1311
"runtime"
1412
"strings"
@@ -119,17 +117,9 @@ func syncGitConfig(ctx context.Context) (err error) {
119117
return err
120118
}
121119

122-
func IsErrorExitCode(err error, code int) bool {
123-
var exitError *exec.ExitError
124-
if errors.As(err, &exitError) {
125-
return exitError.ExitCode() == code
126-
}
127-
return false
128-
}
129-
130120
func configSet(ctx context.Context, key, value string) error {
131121
stdout, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx, nil)
132-
if err != nil && !IsErrorExitCode(err, 1) {
122+
if err != nil && !gitcmd.IsErrorExitCode(err, 1) {
133123
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
134124
}
135125

@@ -152,7 +142,7 @@ func configSetNonExist(ctx context.Context, key, value string) error {
152142
// already exist
153143
return nil
154144
}
155-
if IsErrorExitCode(err, 1) {
145+
if gitcmd.IsErrorExitCode(err, 1) {
156146
// not exist, set new config
157147
_, _, err = gitcmd.NewCommand("config", "--global").AddDynamicArguments(key, value).RunStdString(ctx, nil)
158148
if err != nil {
@@ -170,7 +160,7 @@ func configAddNonExist(ctx context.Context, key, value string) error {
170160
// already exist
171161
return nil
172162
}
173-
if IsErrorExitCode(err, 1) {
163+
if gitcmd.IsErrorExitCode(err, 1) {
174164
// not exist, add new config
175165
_, _, err = gitcmd.NewCommand("config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(ctx, nil)
176166
if err != nil {
@@ -191,7 +181,7 @@ func configUnsetAll(ctx context.Context, key, value string) error {
191181
}
192182
return nil
193183
}
194-
if IsErrorExitCode(err, 1) {
184+
if gitcmd.IsErrorExitCode(err, 1) {
195185
// not exist
196186
return nil
197187
}

modules/git/gitcmd/command.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (c *Command) AddConfig(key, value string) *Command {
185185
}
186186

187187
// ToTrustedCmdArgs converts a list of strings (trusted as argument) to TrustedCmdArgs
188-
// In most cases, it shouldn't be used. Use cmd.NewCommand().AddXxx() function instead
188+
// In most cases, it shouldn't be used. Use NewCommand().AddXxx() function instead
189189
func ToTrustedCmdArgs(args []string) TrustedCmdArgs {
190190
ret := make(TrustedCmdArgs, len(args))
191191
for i, arg := range args {
@@ -389,6 +389,14 @@ func (r *runStdError) Stderr() string {
389389
return r.stderr
390390
}
391391

392+
func IsErrorExitCode(err error, code int) bool {
393+
var exitError *exec.ExitError
394+
if errors.As(err, &exitError) {
395+
return exitError.ExitCode() == code
396+
}
397+
return false
398+
}
399+
392400
// RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
393401
func (c *Command) RunStdString(ctx context.Context, opts *RunOpts) (stdout, stderr string, runErr RunStdError) {
394402
stdoutBytes, stderrBytes, err := c.runStdBytes(ctx, opts)

modules/git/grep.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
136136
},
137137
})
138138
// git grep exits by cancel (killed), usually it is caused by the limit of results
139-
if IsErrorExitCode(err, -1) && stderr.Len() == 0 {
139+
if gitcmd.IsErrorExitCode(err, -1) && stderr.Len() == 0 {
140140
return results, nil
141141
}
142142
// git grep exits with 1 if no results are found
143-
if IsErrorExitCode(err, 1) && stderr.Len() == 0 {
143+
if gitcmd.IsErrorExitCode(err, 1) && stderr.Len() == 0 {
144144
return nil, nil
145145
}
146146
if err != nil && !errors.Is(err, context.Canceled) {

0 commit comments

Comments
 (0)