@@ -93,7 +93,7 @@ func AddChanges(ctx context.Context, repoPath string, all bool, files ...string)
9393 cmd .AddArguments ("--all" )
9494 }
9595 cmd .AddDashesAndList (files ... )
96- _ , _ , err := cmd .RunStdString (ctx , & gitcmd. RunOpts { Dir : repoPath } )
96+ _ , _ , err := cmd .WithDir ( repoPath ). RunStdString (ctx )
9797 return err
9898}
9999
@@ -122,7 +122,7 @@ func CommitChanges(ctx context.Context, repoPath string, opts CommitChangesOptio
122122 }
123123 cmd .AddOptionFormat ("--message=%s" , opts .Message )
124124
125- _ , _ , err := cmd .RunStdString (ctx , & gitcmd. RunOpts { Dir : repoPath } )
125+ _ , _ , err := cmd .WithDir ( repoPath ). RunStdString (ctx )
126126 // No stderr but exit status 1 means nothing to commit.
127127 if err != nil && err .Error () == "exit status 1" {
128128 return nil
@@ -141,7 +141,7 @@ func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, file
141141 cmd .AddDashesAndList (files ... )
142142 }
143143
144- stdout , _ , err := cmd .RunStdString (ctx , & gitcmd. RunOpts { Dir : repoPath } )
144+ stdout , _ , err := cmd .WithDir ( repoPath ). RunStdString (ctx )
145145 if err != nil {
146146 return 0 , err
147147 }
@@ -173,7 +173,7 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
173173 cmd .AddDashesAndList (opts .RelPath ... )
174174 }
175175
176- stdout , _ , err := cmd .RunStdString ( ctx , & gitcmd. RunOpts { Dir : opts .RepoPath } )
176+ stdout , _ , err := cmd .WithDir ( opts .RepoPath ). RunStdString ( ctx )
177177 if err != nil {
178178 return 0 , err
179179 }
@@ -208,7 +208,10 @@ func (c *Commit) HasPreviousCommit(objectID ObjectID) (bool, error) {
208208 return false , nil
209209 }
210210
211- _ , _ , err := gitcmd .NewCommand ("merge-base" , "--is-ancestor" ).AddDynamicArguments (that , this ).RunStdString (c .repo .Ctx , & gitcmd.RunOpts {Dir : c .repo .Path })
211+ _ , _ , err := gitcmd .NewCommand ("merge-base" , "--is-ancestor" ).
212+ AddDynamicArguments (that , this ).
213+ WithDir (c .repo .Path ).
214+ RunStdString (c .repo .Ctx )
212215 if err == nil {
213216 return true , nil
214217 }
@@ -354,7 +357,7 @@ func (c *Commit) GetBranchName() (string, error) {
354357 cmd .AddArguments ("--exclude" , "refs/tags/*" )
355358 }
356359 cmd .AddArguments ("--name-only" , "--no-undefined" ).AddDynamicArguments (c .ID .String ())
357- data , _ , err := cmd .RunStdString (c .repo .Ctx , & gitcmd. RunOpts { Dir : c .repo .Path } )
360+ data , _ , err := cmd .WithDir (c .repo .Path ). RunStdString ( c .repo .Ctx )
358361 if err != nil {
359362 // handle special case where git can not describe commit
360363 if strings .Contains (err .Error (), "cannot describe" ) {
@@ -432,11 +435,12 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
432435 }()
433436
434437 stderr := new (bytes.Buffer )
435- err := gitcmd .NewCommand ("log" , "--name-status" , "-m" , "--pretty=format:" , "--first-parent" , "--no-renames" , "-z" , "-1" ).AddDynamicArguments (commitID ).Run (ctx , & gitcmd.RunOpts {
436- Dir : repoPath ,
437- Stdout : w ,
438- Stderr : stderr ,
439- })
438+ err := gitcmd .NewCommand ("log" , "--name-status" , "-m" , "--pretty=format:" , "--first-parent" , "--no-renames" , "-z" , "-1" ).
439+ AddDynamicArguments (commitID ).
440+ WithDir (repoPath ).
441+ WithStdout (w ).
442+ WithStderr (stderr ).
443+ Run (ctx )
440444 w .Close () // Close writer to exit parsing goroutine
441445 if err != nil {
442446 return nil , gitcmd .ConcatenateError (err , stderr .String ())
@@ -448,7 +452,10 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
448452
449453// GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
450454func GetFullCommitID (ctx context.Context , repoPath , shortID string ) (string , error ) {
451- commitID , _ , err := gitcmd .NewCommand ("rev-parse" ).AddDynamicArguments (shortID ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
455+ commitID , _ , err := gitcmd .NewCommand ("rev-parse" ).
456+ AddDynamicArguments (shortID ).
457+ WithDir (repoPath ).
458+ RunStdString (ctx )
452459 if err != nil {
453460 if strings .Contains (err .Error (), "exit status 128" ) {
454461 return "" , ErrNotExist {shortID , "" }
0 commit comments