mirror of
https://github.com/thegeeklab/wp-git-clone.git
synced 2024-11-10 04:00:39 +00:00
93 lines
1.3 KiB
Go
93 lines
1.3 KiB
Go
|
package git
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"golang.org/x/sys/execabs"
|
||
|
)
|
||
|
|
||
|
// FetchSource fetches the source from remote.
|
||
|
func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd {
|
||
|
tagsOption := "--no-tags"
|
||
|
|
||
|
if tags {
|
||
|
tagsOption = "--tags"
|
||
|
}
|
||
|
|
||
|
args := []string{
|
||
|
"fetch",
|
||
|
tagsOption,
|
||
|
}
|
||
|
|
||
|
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...,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// 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",
|
||
|
"-qf",
|
||
|
"FETCH_HEAD",
|
||
|
}
|
||
|
|
||
|
return execabs.Command(
|
||
|
gitBin,
|
||
|
args...,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// CheckoutSha handles commit checkout.
|
||
|
func CheckoutSha(repo Repository) *execabs.Cmd {
|
||
|
args := []string{
|
||
|
"reset",
|
||
|
"--hard",
|
||
|
"-q",
|
||
|
repo.CommitSha,
|
||
|
}
|
||
|
|
||
|
return execabs.Command(
|
||
|
gitBin,
|
||
|
args...,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// CheckoutLFS handles commit checkout.
|
||
|
func CheckoutLFS() *execabs.Cmd {
|
||
|
args := []string{
|
||
|
"lfs",
|
||
|
"checkout",
|
||
|
}
|
||
|
|
||
|
return execabs.Command(
|
||
|
gitBin,
|
||
|
args...,
|
||
|
)
|
||
|
}
|