-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.go
More file actions
35 lines (30 loc) · 715 Bytes
/
git.go
File metadata and controls
35 lines (30 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import "os/exec"
type Git struct {
RepoURL string
TempDir string
}
func (g *Git) Clone() error {
cmd := exec.Command("git", "clone", "--depth=1", "--filter=blob:none", "--no-checkout", g.RepoURL, g.TempDir)
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (g *Git) SparseCheckout(sources []string) error {
args := append([]string{"sparse-checkout", "set", "--no-cone"}, sources...)
cmd := exec.Command("git", args...)
cmd.Dir = g.TempDir
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (g *Git) Checkout() error {
cmd := exec.Command("git", "checkout", "HEAD")
cmd.Dir = g.TempDir
if err := cmd.Run(); err != nil {
return err
}
return nil
}