0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-24 23:10:40 +00:00
wp-git-clone/git/clone.go

102 lines
1.4 KiB
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"fmt"
"golang.org/x/sys/execabs"
)
// FetchSource fetches the source from remote.
func FetchSource(ref string, depth int, filter string) *execabs.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"fetch",
}
if depth != 0 {
args = append(args, fmt.Sprintf("--depth=%d", depth))
}
if filter != "" {
args = append(args, "--filter="+filter)
}
args = append(args, "origin")
args = append(args, fmt.Sprintf("+%s:", ref))
return execabs.Command(
gitBin,
args...,
)
}
// FetchTags fetches the source from remote.
func FetchTags() *execabs.Cmd {
args := []string{
"fetch",
"--tags",
"--quiet",
"origin",
}
return execabs.Command(
gitBin,
args...,
)
}
2023-12-22 23:59:23 +00:00
// FetchLFS fetches lfs.
func FetchLFS() *execabs.Cmd {
args := []string{
"lfs",
"fetch",
}
return execabs.Command(
gitBin,
args...,
)
}
// CheckoutHead handles head checkout.
func CheckoutHead() *execabs.Cmd {
args := []string{
"checkout",
"--force",
"--quiet",
2023-12-22 23:59:23 +00:00
"FETCH_HEAD",
}
return execabs.Command(
gitBin,
args...,
)
}
// CheckoutSha handles commit checkout.
func CheckoutSha(repo Repository) *execabs.Cmd {
args := []string{
"reset",
"--hard",
"--quiet",
2023-12-22 23:59:23 +00:00
repo.CommitSha,
}
return execabs.Command(
gitBin,
args...,
)
}
// CheckoutLFS handles commit checkout.
func CheckoutLFS() *execabs.Cmd {
args := []string{
"lfs",
"checkout",
}
return execabs.Command(
gitBin,
args...,
)
}