From 934b6e69f4342297a4da7f726615b2bb7192940b Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Sat, 1 Aug 2026 23:34:50 +0200 Subject: [PATCH] fix(dev): shallow clone pull requests --- tools/homarr-dev/internal/run/build.go | 6 +++++- tools/homarr-dev/internal/run/run_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/homarr-dev/internal/run/build.go b/tools/homarr-dev/internal/run/build.go index bf3a45b3c..de78fd291 100644 --- a/tools/homarr-dev/internal/run/build.go +++ b/tools/homarr-dev/internal/run/build.go @@ -41,7 +41,7 @@ func buildPRImage(ctx context.Context, number int, tag string, stdout, stderr io defer os.RemoveAll(temporaryRoot) checkout := filepath.Join(temporaryRoot, "homarr") - clone := exec.CommandContext(ctx, "gh", "repo", "clone", gh.Repo, checkout, "--", "--filter=blob:none") + clone := exec.CommandContext(ctx, "gh", prCloneArgs(checkout)...) clone.Stdout = stdout clone.Stderr = stderr if err := clone.Run(); err != nil { @@ -67,6 +67,10 @@ func buildPRImage(ctx context.Context, number int, tag string, stdout, stderr io }, stdout, stderr) } +func prCloneArgs(checkout string) []string { + return []string{"repo", "clone", gh.Repo, checkout, "--", "--depth=1", "--filter=blob:none"} +} + func RebuildImage(image docker.Image) error { return RebuildImageContext(context.Background(), image, os.Stdout, os.Stderr) } diff --git a/tools/homarr-dev/internal/run/run_test.go b/tools/homarr-dev/internal/run/run_test.go index 1d12d250e..5bed7eac9 100644 --- a/tools/homarr-dev/internal/run/run_test.go +++ b/tools/homarr-dev/internal/run/run_test.go @@ -2,6 +2,7 @@ package run import ( "os" + "slices" "strconv" "testing" @@ -18,6 +19,13 @@ func TestPRPlanUsesAMD64(t *testing.T) { } } +func TestPRCloneIsShallow(t *testing.T) { + args := prCloneArgs("/tmp/checkout") + if !slices.Contains(args, "--depth=1") || !slices.Contains(args, "--filter=blob:none") { + t.Fatalf("clone args = %v", args) + } +} + func TestBuildPlanFailsWhenNoPortIsAvailable(t *testing.T) { _, err := BuildPlan(Options{Tag: "dev", FindPort: func(int) int { return 0 }}) if err == nil {