Borg/pkg/vcs/git.go
google-labs-jules[bot] edc0d6a18c feat: Implement non-interactive quote display
This commit introduces a non-interactive mode for the `collect` commands. When running in a non-interactive session, the progress bar is replaced with a series of thematic Borg quotes, printed in matrix-green text.

The quotes are sourced from a `quotes.json` file, which is embedded into the binary using Go's `embed` package. The `pkg/ui` package now contains a `NonInteractivePrompter` that detects the session type and displays the quotes accordingly. The `collect` commands have been updated to use this new prompter, and the underlying `vcs` and `website` packages have been made more robust to handle cases where a progress bar is not provided.
2025-11-02 16:34:45 +00:00

56 lines
1 KiB
Go

package vcs
import (
"io"
"os"
"path/filepath"
"github.com/Snider/Borg/pkg/datanode"
"github.com/go-git/go-git/v5"
)
// CloneGitRepository clones a Git repository from a URL and packages it into a DataNode.
func CloneGitRepository(repoURL string, progress io.Writer) (*datanode.DataNode, error) {
tempPath, err := os.MkdirTemp("", "borg-clone-*")
if err != nil {
return nil, err
}
defer os.RemoveAll(tempPath)
cloneOptions := &git.CloneOptions{
URL: repoURL,
}
if progress != nil {
cloneOptions.Progress = progress
}
_, err = git.PlainClone(tempPath, false, cloneOptions)
if err != nil {
return nil, err
}
dn := datanode.New()
err = filepath.Walk(tempPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
content, err := os.ReadFile(path)
if err != nil {
return err
}
relPath, err := filepath.Rel(tempPath, path)
if err != nil {
return err
}
dn.AddData(relPath, content)
}
return nil
})
if err != nil {
return nil, err
}
return dn, nil
}