@@ -5,10 +5,8 @@ package git
55
66import  (
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- 
130120func  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	}
0 commit comments