diff --git a/buildkit/Dockerfile b/buildkit/Dockerfile index f6b4a4e7c14..a2e2df56ae0 100644 --- a/buildkit/Dockerfile +++ b/buildkit/Dockerfile @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.14.1 COPY \ backport-5072-fetch-tags.patch \ containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.0.13 b/buildkit/Dockerfile.0.13 index fc1a2c7b89c..7fcb201f45b 100644 --- a/buildkit/Dockerfile.0.13 +++ b/buildkit/Dockerfile.0.13 @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.13.2 COPY \ backport-5072-fetch-tags.patch \ containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.rc b/buildkit/Dockerfile.rc index ab43e001025..988aa7c44ac 100644 --- a/buildkit/Dockerfile.rc +++ b/buildkit/Dockerfile.rc @@ -12,6 +12,7 @@ ENV BUILDKIT_VERSION 0.14.0-rc2 COPY \ backport-5072-fetch-tags.patch \ containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/Dockerfile.template b/buildkit/Dockerfile.template index f2a4e7d4883..b2203cd53f1 100644 --- a/buildkit/Dockerfile.template +++ b/buildkit/Dockerfile.template @@ -17,6 +17,7 @@ COPY \ backport-5072-fetch-tags.patch \ {{ ) else "" end -}} containerd-arm64-v8.patch \ + git-fetch-by-commit.patch \ git-no-submodules.patch \ mips64le.patch \ noclip.patch \ diff --git a/buildkit/git-fetch-by-commit.patch b/buildkit/git-fetch-by-commit.patch new file mode 100644 index 00000000000..12428d9ce0e --- /dev/null +++ b/buildkit/git-fetch-by-commit.patch @@ -0,0 +1,20 @@ +Description: try fetching by commit, then regular fall back to deeper fetching +Forwarded: no + +diff --git a/source/git/source.go b/source/git/source.go +index d139942fc..700982bd6 100644 +--- a/source/git/source.go ++++ b/source/git/source.go +@@ -459,6 +459,12 @@ func (gs *gitSourceHandler) Snapshot(ctx context.Context, g session.Group) (out + // skip fetch if commit already exists + if _, err := git.Run(ctx, "cat-file", "-e", ref+"^{commit}"); err == nil { + doFetch = false ++ } else { ++ // try fetching commit directly ++ // TODO limit to known working git hosts? ++ if _, err := git.Run(ctx, "fetch", "origin", ref+":"); err == nil { ++ doFetch = false ++ } + } + } +