From 929b8444e41084541d7f439f4eaa4f7ce6d13100 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Wed, 1 Oct 2025 00:27:08 +0300 Subject: [PATCH] Add helper functions isBareGitRepo and checkoutBareGitRepo --- plugins/buildpacks/functions.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/buildpacks/functions.go b/plugins/buildpacks/functions.go index f3545233e..0252e239e 100644 --- a/plugins/buildpacks/functions.go +++ b/plugins/buildpacks/functions.go @@ -63,3 +63,31 @@ func validBuildpackURL(buildpack string) (string, error) { return buildpack, fmt.Errorf("Invalid buildpack specified: %v", buildpack) } + +func isBareGitRepo(directory string) bool { + headFile := filepath.Join(directory, "HEAD") + objectsDir := filepath.Join(directory, "objects") + if common.FileExists(headFile) && common.DirectoryExists(objectsDir) { + return true + } + return false +} + +func checkoutBareGitRepo(sourceWorkDir string) (string, error) { + tmpdir, err := os.MkdirTemp("", "bare-git-checkout") + if err != nil { + return "", fmt.Errorf("Unable to create temporary directory: %s", err.Error()) + } + + result, err := common.CallExecCommand(common.ExecCommandInput{ + Command: "git", + Args: []string{"--git-dir=" + sourceWorkDir, "--work-tree=" + tmpdir, "checkout", "-f"}, + }) + + if err != nil { + os.RemoveAll(tmpdir) + return "", fmt.Errorf("Unable to checkout bare git repository: %s", result.StderrContents()) + } + + return tmpdir, nil +}