Skip to content

Commit bebdfa4

Browse files
committed
feat: support copy to custom directory
1 parent 6ce4fd9 commit bebdfa4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pkg/git/v2/client_factory.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ type RepoOpts struct {
152152
// branch name and SHA pairs will be fed into RetargetBranch in the git v2
153153
// client, to update the current HEAD of each branch.
154154
BranchesToRetarget map[string]string
155+
// CopyTo specifies the target directory to put the copy of the repository.
156+
// If not set, the client will create and use a temporary directory.
157+
CopyTo string
155158
}
156159

157160
// Apply allows to use a ClientFactoryOpts as Opt
@@ -377,10 +380,18 @@ func (c *clientFactory) ClientForWithRepoOpts(org, repo string, repoOpts RepoOpt
377380
return nil, err
378381
}
379382

380-
// Put copies of the repo in temp dir.
381-
repoDir, err := os.MkdirTemp(*defaultTempDir(), "gitrepo")
382-
if err != nil {
383-
return nil, err
383+
var repoDir string
384+
if repoOpts.CopyTo != "" {
385+
if err := os.MkdirAll(repoOpts.CopyTo, 0700); err != nil {
386+
return nil, fmt.Errorf("failed to create directory %s: %w", repoOpts.CopyTo, err)
387+
}
388+
repoDir = repoOpts.CopyTo
389+
} else {
390+
// Put copies of the repo in temp dir.
391+
repoDir, err = os.MkdirTemp(*defaultTempDir(), "gitrepo")
392+
if err != nil {
393+
return nil, err
394+
}
384395
}
385396
_, repoClientCloner, repoClient, err := c.bootstrapClients(org, repo, repoDir)
386397
if err != nil {

0 commit comments

Comments
 (0)