Skip to content

Commit

Permalink
Merge pull request #294 from cpanato/update-preparefork
Browse files Browse the repository at this point in the history
add options to preparefork to when you need to configure special things
  • Loading branch information
k8s-ci-robot committed Dec 22, 2023
2 parents 0346149 + 5477ab2 commit f8ebf35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,19 @@ func CloneOrOpenDefaultGitHubRepoSSH(repoPath string) (*Repo, error) {

// CleanCloneGitHubRepo creates a guaranteed fresh checkout of a given repository. The returned *Repo has a Cleanup()
// method that should be used to delete the repository on-disk afterwards.
func CleanCloneGitHubRepo(owner, repo string, useSSH bool) (*Repo, error) {
func CleanCloneGitHubRepo(owner, repo string, useSSH bool, opts *git.CloneOptions) (*Repo, error) {
repoURL := GetRepoURL(owner, repo, useSSH)
// The use of a blank string for the repo path triggers special behaviour in CloneOrOpenRepo that causes a true
// temporary directory with a random name to be created.
return CloneOrOpenRepo("", repoURL, useSSH)
return CloneOrOpenRepo("", repoURL, useSSH, opts)
}

// CloneOrOpenGitHubRepo works with a repository in the given directory, or creates one if the directory is empty. The
// repo uses the provided GitHub repository via the owner and repo. If useSSH is true, then it will clone the
// repository using the defaultGithubAuthRoot.
func CloneOrOpenGitHubRepo(repoPath, owner, repo string, useSSH bool) (*Repo, error) {
repoURL := GetRepoURL(owner, repo, useSSH)
return CloneOrOpenRepo(repoPath, repoURL, useSSH)
return CloneOrOpenRepo(repoPath, repoURL, useSSH, nil)
}

// ShallowCleanCloneGitHubRepo creates a guaranteed fresh checkout of a GitHub
Expand Down Expand Up @@ -425,8 +425,8 @@ func ShallowCloneOrOpenRepo(repoPath, repoURL string, useSSH bool) (*Repo, error
//
// The function returns the repository if cloning or updating of the repository
// was successful, otherwise an error.
func CloneOrOpenRepo(repoPath, repoURL string, useSSH bool) (*Repo, error) { //nolint: revive
return cloneOrOpenRepo(repoPath, repoURL, nil)
func CloneOrOpenRepo(repoPath, repoURL string, useSSH bool, opts *git.CloneOptions) (*Repo, error) { //nolint: revive
return cloneOrOpenRepo(repoPath, repoURL, opts)
}

// cloneOrOpenRepo checks that the repoPath exists or creates it before running the
Expand Down
4 changes: 2 additions & 2 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func TestFetchRemote(t *testing.T) {
defer originRepo.Cleanup() //nolint: errcheck

// Create a new clone of the original repo
testRepo, err := git.CloneOrOpenRepo("", rawRepoDir, false)
testRepo, err := git.CloneOrOpenRepo("", rawRepoDir, false, nil)
require.Nil(t, err)
defer testRepo.Cleanup() //nolint: errcheck

Expand Down Expand Up @@ -530,7 +530,7 @@ func TestRebase(t *testing.T) {
defer originRepo.Cleanup() //nolint: errcheck

// Create a new clone of the original repo
testRepo, err := git.CloneOrOpenRepo("", rawRepoDir, false)
testRepo, err := git.CloneOrOpenRepo("", rawRepoDir, false, nil)
require.Nil(t, err)
defer testRepo.Cleanup() //nolint: errcheck

Expand Down
5 changes: 3 additions & 2 deletions github/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package github
import (
"fmt"

gogit "github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"

"sigs.k8s.io/release-sdk/git"
Expand All @@ -31,12 +32,12 @@ const (
)

// PrepareFork prepares a branch from a repo fork
func PrepareFork(branchName, upstreamOrg, upstreamRepo, myOrg, myRepo string, useSSH bool) (repo *git.Repo, err error) {
func PrepareFork(branchName, upstreamOrg, upstreamRepo, myOrg, myRepo string, useSSH bool, opts *gogit.CloneOptions) (repo *git.Repo, err error) {
// checkout the upstream repository
logrus.Infof("Cloning/updating repository %s/%s", upstreamOrg, upstreamRepo)

repo, err = git.CleanCloneGitHubRepo(
upstreamOrg, upstreamRepo, false,
upstreamOrg, upstreamRepo, false, opts,
)
if err != nil {
return nil, fmt.Errorf("cloning %s/%s: %w", upstreamOrg, upstreamRepo, err)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func newTestRepo(t *testing.T) *testRepo {
require.Nil(t, os.RemoveAll(cloneTempDir))

// Provide a system under test inside the test repo
sut, err := git.CloneOrOpenRepo("", bareTempDir, false)
sut, err := git.CloneOrOpenRepo("", bareTempDir, false, nil)
require.Nil(t, err)
require.Nil(t, command.NewWithWorkDir(
sut.Dir(), "git", "checkout", branchName,
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestSuccessCloneOrOpen(t *testing.T) {
testRepo := newTestRepo(t)
defer testRepo.cleanup(t)

secondRepo, err := git.CloneOrOpenRepo(testRepo.sut.Dir(), testRepo.dir, false)
secondRepo, err := git.CloneOrOpenRepo(testRepo.sut.Dir(), testRepo.dir, false, nil)
require.Nil(t, err)

require.Equal(t, secondRepo.Dir(), testRepo.sut.Dir())
Expand Down

0 comments on commit f8ebf35

Please sign in to comment.