2022-12-02 21:21:35 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-05-17 19:49:59 +00:00
|
|
|
"os"
|
2023-02-08 09:16:10 +00:00
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
2022-12-02 21:21:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FetchSource fetches the source from remote.
|
2024-05-17 19:49:59 +00:00
|
|
|
func (r *Repository) FetchSource() *plugin_exec.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2022-12-02 21:21:35 +00:00
|
|
|
"fetch",
|
|
|
|
"origin",
|
2024-05-06 18:29:57 +00:00
|
|
|
fmt.Sprintf("+%s:", r.Branch),
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd.Dir = r.WorkDir
|
2022-12-02 21:21:35 +00:00
|
|
|
|
2024-05-06 20:43:56 +00:00
|
|
|
return cmd
|
2022-12-02 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutHead handles branch checkout.
|
2024-05-17 19:49:59 +00:00
|
|
|
func (r *Repository) CheckoutHead() *plugin_exec.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2022-12-02 21:21:35 +00:00
|
|
|
"checkout",
|
|
|
|
"-qf",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.Branch,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd.Dir = r.WorkDir
|
2022-12-02 21:21:35 +00:00
|
|
|
|
2024-05-06 20:43:56 +00:00
|
|
|
return cmd
|
2022-12-02 21:21:35 +00:00
|
|
|
}
|