Repository: jenkins-x/lighthouse
Pull request #1472 (2022-08-25 11:40:39)

fix: Reuse sparse checkout
It seems like --depth-1 is a bit to aggressive to work properly. Also it implies --single-branch, which means that checking out another branch might fail. To mitigate this I add --no-single-branch

jenkins-x-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **tomhobson**
You can assign the PR to them by writing `/assign @tomhobson` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://jenkins-x.io/v3/develop/reference/chatops/?repo=jenkins-x%2Flighthouse).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/jenkins-x/lighthouse/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["tomhobson"]} -->
jenkins-x-bot: @msvticket: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pr | d57acd3cc3f43a2b137a5a5547d3ab0bb83ce00f | [link](http://dashboard-jx.infra.jenkins-x.rocks/namespaces/jx/pipelineruns/jenkins-x-lighthouse-pr-1472-pr-zxfm5) | `/test`



<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [jenkins-x/lighthouse](https://github.com/jenkins-x/lighthouse/issues/new?title=Command%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/OWNERS b/OWNERS
index 28f73bad..912e2d5d 100644
--- a/OWNERS
+++ b/OWNERS
@@ -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
\ No newline at end of file
diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES
new file mode 100644
index 00000000..74e652b4
--- /dev/null
+++ b/OWNERS_ALIASES
@@ -0,0 +1,3 @@
+foreignAliases:
+- name: jx-community
+  org: jenkins-x
diff --git a/pkg/git/git.go b/pkg/git/git.go
index b146ef21..d7404ef9 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -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 {
@@ -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))
 		}
 	}
diff --git a/pkg/git/v2/interactor.go b/pkg/git/v2/interactor.go
index feec1f12..e8746668 100644
--- a/pkg/git/v2/interactor.go
+++ b/pkg/git/v2/interactor.go
@@ -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")
 	}
@@ -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))


Test patch:
diff --git a/pkg/git/v2/interactor_test.go b/pkg/git/v2/interactor_test.go
index b1811434..2dcebfa0 100644
--- a/pkg/git/v2/interactor_test.go
+++ b/pkg/git/v2/interactor_test.go
@@ -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,
 		},
@@ -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,
 		},
@@ -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,
 		},
@@ -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,
 		},