Add helper functions isBareGitRepo and checkoutBareGitRepo

This commit is contained in:
Tasos Maschalidis authored and Tasos Maschalidis committed 2025-10-16 17:27:37 +03:00
1 parent fc9a0aeefd
commit 929b8444e4
1 file changed
+28
+28
View File
@@ -63,3 +63,31 @@ func validBuildpackURL(buildpack string) (string, error) {
return buildpack, fmt.Errorf("Invalid buildpack specified: %v", buildpack) 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
}