sketch/loop: handle existing git repos in innie sketch
Check if /app/.git already exists before attempting to clone. If it exists
(e.g., from skaband images or user images with existing git repos), configure
the origin remote and fetch instead of cloning.
This fixes compatibility with skaband dockerfiles that create images with
existing git repositories, and adapts to the object-only approach introduced
in commit 9e8f5c78e8cef4c73e7b2629b2270ab572d530f8.
The implementation uses a helper function upsertRemoteOrigin that handles
both setting the URL for existing origin remotes and adding new ones.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s9625bfa389b6b7dek
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 18284b1..2ada9c6 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -809,11 +809,8 @@
// We also set up fake temporary Go module(s) so we can run "go mod download".
// TODO: maybe 'go list ./...' and then do a build as well to populate the build cache.
// TODO: 'npm install', etc? We have the rails for it.
-// This is an ok compromise, but a power user might want
-// less caching or more caching, depending on their use case. One approach we could take
-// is to punt entirely if /app/.git already exists. If the user has provided a -base-image with
-// their git repo, let's assume they know what they're doing, and they've customized their image
-// for their use case.
+// If /app/.git already exists, we fetch from the existing repo instead of cloning.
+// This lets advanced users arrange their git repo exactly as they desire.
// Note that buildx has some support for conditional COPY, but without buildx, which
// we can't reliably depend on, we have to run the base image to inspect its file system,
// and then we can decide what to do.