Skip to content

Commit ad9fefc

Browse files
author
openshift-pipelines-bot
committed
[bot] Update release-v1.21.x from tektoncd-catalog/git-clone to b538d80
$ git diff --stat b538d80..768a778 .github/workflows/build.yaml | 4 +- .github/workflows/release.yaml | 4 +- image/git-init/git/git.go | 22 +++------- image/git-init/git/git_test.go | 94 +----------------------------------------- 4 files changed, 11 insertions(+), 113 deletions(-) https://github.com/tektoncd-catalog/git-clone/compare/b538d805a95b63905601c9f7a03283308abf1b6f..768a778f1f7ccee8a4dd142e7f115e12c7e422fd
1 parent f5bbd60 commit ad9fefc

File tree

5 files changed

+114
-12
lines changed

5 files changed

+114
-12
lines changed

head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
768a778f1f7ccee8a4dd142e7f115e12c7e422fd
1+
b538d805a95b63905601c9f7a03283308abf1b6f

upstream/.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
runs-on: ubuntu-latest
2020

2121
steps:
22-
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
23-
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
22+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
2424
with:
2525
go-version-file: "image/git-init/go.mod"
2626
cache-dependency-path: "image/git-init/go.sum"

upstream/.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ jobs:
2626
# run:
2727
# working-directory: ./image/git-init
2828
steps:
29-
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
29+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3030

3131
- run: git fetch --prune --unshallow
3232

33-
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
33+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
3434
with:
3535
go-version-file: "image/git-init/go.mod"
3636
cache-dependency-path: "image/git-init/go.sum"

upstream/image/git-init/git/git.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec, retryConfig RetryConfig) e
167167
}
168168
if spec.Depth > 0 {
169169
fetchArgs = append(fetchArgs, fmt.Sprintf("--depth=%d", spec.Depth))
170+
171+
// Prevent fetching of unrelated git objects with shallow clones.
172+
if _, err := run(logger, "", "config", "--unset", "remote.origin.fetch"); err != nil {
173+
logger.Warnf("Failed to unset remote.origin.fetch in git config: %s", err)
174+
}
170175
}
171176

172177
// Fetch the revision and verify with FETCH_HEAD
@@ -241,19 +246,24 @@ func showRef(logger *zap.SugaredLogger, revision, path string) (string, error) {
241246
return strings.TrimSuffix(output, "\n"), nil
242247
}
243248

244-
func submoduleFetch(logger *zap.SugaredLogger, spec FetchSpec, retryConfig RetryConfig) error {
245-
if spec.Path != "" {
246-
if err := os.Chdir(spec.Path); err != nil {
247-
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
248-
}
249-
}
249+
func buildSubmoduleUpdateArgs(spec FetchSpec) []string {
250250
updateArgs := []string{"submodule", "update", "--recursive", "--init", "--force"}
251251
if spec.Depth > 0 {
252252
updateArgs = append(updateArgs, fmt.Sprintf("--depth=%d", spec.Depth))
253253
}
254254
if len(spec.SubmodulePaths) > 0 {
255255
updateArgs = append(updateArgs, spec.SubmodulePaths...)
256256
}
257+
return updateArgs
258+
}
259+
260+
func submoduleFetch(logger *zap.SugaredLogger, spec FetchSpec, retryConfig RetryConfig) error {
261+
if spec.Path != "" {
262+
if err := os.Chdir(spec.Path); err != nil {
263+
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
264+
}
265+
}
266+
updateArgs := buildSubmoduleUpdateArgs(spec)
257267
if _, _, err := retryWithBackoff(
258268
func() (string, error) { return run(logger, "", updateArgs...) },
259269
retryConfig.Initial,

upstream/image/git-init/git/git_test.go

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ func TestFetch(t *testing.T) {
361361
HTTPSProxy: "",
362362
NOProxy: "",
363363
},
364+
}, {
365+
name: "test-clone-with-depth",
366+
logMessage: "Successfully cloned",
367+
wantErr: false,
368+
spec: FetchSpec{
369+
URL: "",
370+
Revision: "",
371+
Refspec: "",
372+
Path: "",
373+
Depth: 1,
374+
Submodules: false,
375+
SSLVerify: false,
376+
HTTPProxy: "",
377+
HTTPSProxy: "",
378+
NOProxy: "",
379+
SparseCheckoutDirectories: "",
380+
},
364381
},
365382
}
366383
for _, tt := range tests {
@@ -372,6 +389,7 @@ func TestFetch(t *testing.T) {
372389
}
373390
}()
374391
logger := zap.New(observer).Sugar()
392+
logLine := 1
375393

376394
submodPath := ""
377395
submodName := "default"
@@ -421,10 +439,42 @@ func TestFetch(t *testing.T) {
421439
t.Errorf("directory patterns and sparse-checkout patterns do not match")
422440
}
423441
}
424-
logLine := 1
442+
443+
if tt.spec.Depth > 0 {
444+
shallowFile, err := os.Open(".git/shallow")
445+
if err != nil {
446+
t.Fatal("Faile to read shallow file")
447+
}
448+
defer shallowFile.Close()
449+
450+
var commitCount int
451+
scanner := bufio.NewScanner(shallowFile)
452+
for scanner.Scan() {
453+
commitCount++
454+
}
455+
if commitCount != int(tt.spec.Depth) {
456+
t.Errorf("Expected %d commits in shallow file, got %d", tt.spec.Depth, commitCount)
457+
}
458+
459+
// Verify remote.origin.fetch was unset
460+
_, err = run(logger, "", "config", "--get", "remote.origin.fetch")
461+
if err == nil {
462+
t.Error("git fetch config should be unset for a shallow clone")
463+
}
464+
}
465+
425466
if tt.spec.Submodules {
467+
submoduleDirs, err := filepath.Glob(".git/modules/*")
468+
if err != nil {
469+
t.Fatalf("Error finding submodule directories: %v", err)
470+
}
471+
472+
if len(submoduleDirs) == 0 {
473+
t.Error("No cloned submodules found")
474+
}
426475
logLine = 3
427476
}
477+
428478
checkLogMessage(t, tt.logMessage, log, logLine)
429479
})
430480
}
@@ -510,6 +560,48 @@ func (f *SucceedAfter) Run() (string, error) {
510560
return "", fmt.Errorf("temporary error")
511561
}
512562

563+
func TestBuildSubmoduleUpdateArgs(t *testing.T) {
564+
tests := []struct {
565+
name string
566+
spec FetchSpec
567+
expected []string
568+
}{
569+
{
570+
name: "no depth, no submodule paths",
571+
spec: FetchSpec{
572+
Depth: 0,
573+
SubmodulePaths: nil,
574+
},
575+
expected: []string{"submodule", "update", "--recursive", "--init", "--force"},
576+
},
577+
{
578+
name: "with depth, no submodule paths",
579+
spec: FetchSpec{
580+
Depth: 5,
581+
SubmodulePaths: nil,
582+
},
583+
expected: []string{"submodule", "update", "--recursive", "--init", "--force", "--depth=5"},
584+
},
585+
{
586+
name: "no depth, with submodule paths",
587+
spec: FetchSpec{
588+
Depth: 0,
589+
SubmodulePaths: []string{"path/to/submod1", "path/to/submod2"},
590+
},
591+
expected: []string{"submodule", "update", "--recursive", "--init", "--force", "path/to/submod1", "path/to/submod2"},
592+
},
593+
}
594+
595+
for _, tt := range tests {
596+
t.Run(tt.name, func(t *testing.T) {
597+
got := buildSubmoduleUpdateArgs(tt.spec)
598+
if diff := cmp.Diff(tt.expected, got); diff != "" {
599+
t.Errorf("buildSubmoduleUpdateArgs() mismatch (-want +got):\n%s", diff)
600+
}
601+
})
602+
}
603+
}
604+
513605
func TestRetryWithBackoff(t *testing.T) {
514606
withTemporaryGitConfig(t)
515607
tests := []struct {

0 commit comments

Comments
 (0)