33 lines
741 B
Go
33 lines
741 B
Go
package gitcmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func CloneBare(ctx context.Context, srcPath, destPath string) error {
|
|
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
|
|
return err
|
|
}
|
|
_, stderr, err := NewCommand("clone", "--bare").
|
|
AddDynamicArguments(srcPath, destPath).
|
|
RunStdString(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("git clone --bare %s %s: %w: %s", srcPath, destPath, err, strings.TrimSpace(stderr))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func InitBare(ctx context.Context, repoPath string) error {
|
|
if err := os.MkdirAll(filepath.Dir(repoPath), 0o755); err != nil {
|
|
return err
|
|
}
|
|
_, _, err := NewCommand("init", "--bare").
|
|
AddDynamicArguments(repoPath).
|
|
RunStdString(ctx)
|
|
return err
|
|
}
|