0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-25 09:20:40 +00:00
wp-git-clone/git/clone.go

97 lines
1.6 KiB
Go
Raw Normal View History

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