Skip to content

Commit

Permalink
Merge pull request #1472 from jenkins-x/sparse2
Browse files Browse the repository at this point in the history
fix: Reuse sparse checkout
  • Loading branch information
jenkins-x-bot authored Aug 31, 2022
2 parents 2710db8 + 14dd8ed commit 6bfea59
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 48 deletions.
38 changes: 2 additions & 36 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
approvers:
- abayer
- cagiti
- ccojocar
- daveconde
- dgozalo
- eddycharly
- garethjevans
- hferentschik
- jstrachan
- macox
- mrageh
- pmuir
- rawlingsj
- warrenbailey
- wbrefvem
- ankitm123
- tomhobson
- babadofar
- maintainers
reviewers:
- abayer
- cagiti
- ccojocar
- daveconde
- dgozalo
- eddycharly
- garethjevans
- hferentschik
- jstrachan
- macox
- mrageh
- pmuir
- rawlingsj
- warrenbailey
- wbrefvem
- ankitm123
- tomhobson
- babadofar
- maintainers
3 changes: 3 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foreignAliases:
- name: jx-community
org: jenkins-x
4 changes: 2 additions & 2 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *client) SparseClone(repo string, sparseCheckoutPatterns []string) (*Rep
}
remote := getRemote(repo, c, base)

if b, err := retryCmd(c.logger, "", c.git, "clone", "--no-checkout", "--filter=blob:none", "--sparse", "--depth=1", remote, cache); err != nil {
if b, err := retryCmd(c.logger, "", c.git, "clone", "--no-checkout", "--filter=blob:none", "--sparse", "--depth=10", "--no-single-branch", remote, cache); err != nil {
return nil, fmt.Errorf("failed to clone repository: %v. output: %s", err, string(b))
}
if b, err := retryCmd(c.logger, cache, c.git, append([]string{"sparse-checkout", "set"}, sparseCheckoutPatterns...)...); err != nil {
Expand All @@ -217,7 +217,7 @@ func (c *client) SparseClone(repo string, sparseCheckoutPatterns []string) (*Rep
} else {
// Cache hit. Do a git fetch to keep updated.
c.logger.Infof("Fetching %s.", repo)
if b, err := retryCmd(c.logger, cache, c.git, "fetch", "--depth=1"); err != nil {
if b, err := retryCmd(c.logger, cache, c.git, "fetch", "--depth=10"); err != nil {
return nil, fmt.Errorf("git fetch error: %v. output: %s", err, string(b))
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/git/v2/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (i *interactor) Clean() error {
func (i *interactor) Clone(repo string) error {
sparseCheckout, _ := strconv.ParseBool(os.Getenv("SPARSE_CHECKOUT"))
i.logger.Debugf("Creating a clone of the repo at %s from %s", i.dir, repo)
args := []string{"clone", "--no-checkout", "--depth=1"}
args := []string{"clone", "--no-checkout", "--depth=10", "--no-single-branch"}
if sparseCheckout {
args = append(args, "--filter=blob:none")
}
Expand All @@ -143,7 +143,7 @@ func (i *interactor) MirrorClone() error {
if err != nil {
return fmt.Errorf("could not resolve remote for cloning: %v", err)
}
out, err := i.executor.Run("clone", "--mirror", "--depth=1", remote, i.dir)
out, err := i.executor.Run("clone", "--mirror", "--depth=10", "--no-single-branch", remote, i.dir)
if err != nil {
// the returned error is not being reported
i.logger.Errorf("error creating a mirror clone: %v %v", err, string(out))
Expand Down
16 changes: 8 additions & 8 deletions pkg/git/v2/interactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func TestInteractor_Clone(t *testing.T) {
dir: "/else",
from: "/somewhere",
responses: map[string]execResponse{
"clone --no-checkout --depth=1 /somewhere /else": {
"clone --no-checkout --depth=10 --no-single-branch /somewhere /else": {
out: []byte(`ok`),
},
},
expectedCalls: [][]string{
{"clone", "--no-checkout", "--depth=1", "/somewhere", "/else"},
{"clone", "--no-checkout", "--depth=10", "--no-single-branch", "/somewhere", "/else"},
},
expectedErr: false,
},
Expand All @@ -56,12 +56,12 @@ func TestInteractor_Clone(t *testing.T) {
dir: "/else",
from: "/somewhere",
responses: map[string]execResponse{
"clone --no-checkout --depth=1 /somewhere /else": {
"clone --no-checkout --depth=10 --no-single-branch /somewhere /else": {
err: errors.New("oops"),
},
},
expectedCalls: [][]string{
{"clone", "--no-checkout", "--depth=1", "/somewhere", "/else"},
{"clone", "--no-checkout", "--depth=10", "--no-single-branch", "/somewhere", "/else"},
},
expectedErr: true,
},
Expand Down Expand Up @@ -109,12 +109,12 @@ func TestInteractor_MirrorClone(t *testing.T) {
return "someone.com", nil
},
responses: map[string]execResponse{
"clone --mirror --depth=1 someone.com /else": {
"clone --mirror --depth=10 --no-single-branch someone.com /else": {
out: []byte(`ok`),
},
},
expectedCalls: [][]string{
{"clone", "--mirror", "--depth=1", "someone.com", "/else"},
{"clone", "--mirror", "--depth=10", "--no-single-branch", "someone.com", "/else"},
},
expectedErr: false,
},
Expand All @@ -135,12 +135,12 @@ func TestInteractor_MirrorClone(t *testing.T) {
return "someone.com", nil
},
responses: map[string]execResponse{
"clone --mirror --depth=1 someone.com /else": {
"clone --mirror --depth=10 --no-single-branch someone.com /else": {
err: errors.New("oops"),
},
},
expectedCalls: [][]string{
{"clone", "--mirror", "--depth=1", "someone.com", "/else"},
{"clone", "--mirror", "--depth=10", "--no-single-branch", "someone.com", "/else"},
},
expectedErr: true,
},
Expand Down

0 comments on commit 6bfea59

Please sign in to comment.