Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support copy repository to custom directory #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/git/v2/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ type RepoOpts struct {
// branch name and SHA pairs will be fed into RetargetBranch in the git v2
// client, to update the current HEAD of each branch.
BranchesToRetarget map[string]string
// CopyTo specifies the target directory to put the copy of the repository.
// If not set, the client will create and use a temporary directory.
CopyTo string
}

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

// Put copies of the repo in temp dir.
repoDir, err := os.MkdirTemp(*defaultTempDir(), "gitrepo")
if err != nil {
return nil, err
var repoDir string
if repoOpts.CopyTo != "" {
if err := os.MkdirAll(repoOpts.CopyTo, 0700); err != nil {
return nil, fmt.Errorf("failed to create directory %s: %w", repoOpts.CopyTo, err)
}
repoDir = repoOpts.CopyTo
} else {
// Put copies of the repo in temp dir.
repoDir, err = os.MkdirTemp(*defaultTempDir(), "gitrepo")
if err != nil {
return nil, err
}
}
_, repoClientCloner, repoClient, err := c.bootstrapClients(org, repo, repoDir)
if err != nil {
Expand Down