2023-12-22 23:59:23 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-05-17 19:50:05 +00:00
|
|
|
"os"
|
2023-12-22 23:59:23 +00:00
|
|
|
|
2024-05-17 19:50:05 +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.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) FetchSource(ref string) *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"fetch",
|
|
|
|
}
|
|
|
|
|
2024-05-06 18:30:18 +00:00
|
|
|
if r.Depth != 0 {
|
|
|
|
args = append(args, fmt.Sprintf("--depth=%d", r.Depth))
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 18:30:18 +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))
|
|
|
|
|
2024-05-17 19:50:05 +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
|
|
|
}
|
|
|
|
|
2023-12-23 21:54:17 +00:00
|
|
|
// FetchTags fetches the source from remote.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) FetchTags() *plugin_exec.Cmd {
|
2023-12-23 21:54:17 +00:00
|
|
|
args := []string{
|
|
|
|
"fetch",
|
|
|
|
"--tags",
|
|
|
|
"--quiet",
|
|
|
|
"origin",
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
|
|
|
return cmd
|
2023-12-23 21:54:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 23:59:23 +00:00
|
|
|
// FetchLFS fetches lfs.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) FetchLFS() *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"lfs",
|
|
|
|
"fetch",
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +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
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutHead handles head checkout.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) CheckoutHead() *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"checkout",
|
2023-12-23 21:54:17 +00:00
|
|
|
"--force",
|
|
|
|
"--quiet",
|
2023-12-22 23:59:23 +00:00
|
|
|
"FETCH_HEAD",
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +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
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutSha handles commit checkout.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) CheckoutSha() *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"reset",
|
|
|
|
"--hard",
|
2023-12-23 21:54:17 +00:00
|
|
|
"--quiet",
|
2024-05-06 18:30:18 +00:00
|
|
|
r.CommitSha,
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +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.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) CheckoutLFS() *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"lfs",
|
|
|
|
"checkout",
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +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
|
|
|
}
|