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

109 lines
1.8 KiB
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"fmt"
"os"
2023-12-22 23:59:23 +00:00
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
2023-12-22 23:59:23 +00:00
)
// FetchSource fetches the source from remote.
func (r *Repository) FetchSource(ref string) *plugin_exec.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))
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
2023-12-22 23:59:23 +00:00
}
// FetchTags fetches the source from remote.
func (r *Repository) FetchTags() *plugin_exec.Cmd {
args := []string{
"fetch",
"--tags",
"--quiet",
"origin",
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
2023-12-22 23:59:23 +00:00
// FetchLFS fetches lfs.
func (r *Repository) FetchLFS() *plugin_exec.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"lfs",
"fetch",
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
2023-12-22 23:59:23 +00:00
}
// CheckoutHead handles head checkout.
func (r *Repository) CheckoutHead() *plugin_exec.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"checkout",
"--force",
"--quiet",
2023-12-22 23:59:23 +00:00
"FETCH_HEAD",
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
2023-12-22 23:59:23 +00:00
}
// CheckoutSha handles commit checkout.
func (r *Repository) CheckoutSha() *plugin_exec.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"reset",
"--hard",
"--quiet",
r.CommitSha,
2023-12-22 23:59:23 +00:00
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
2023-12-22 23:59:23 +00:00
}
// CheckoutLFS handles commit checkout.
func (r *Repository) CheckoutLFS() *plugin_exec.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"lfs",
"checkout",
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
2023-12-22 23:59:23 +00:00
}