2022-12-02 22:21:35 +01:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-02-08 10:16:10 +01:00
|
|
|
|
2024-05-05 22:14:55 +02:00
|
|
|
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
2023-02-08 10:16:10 +01:00
|
|
|
"golang.org/x/sys/execabs"
|
2022-12-02 22:21:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// FetchSource fetches the source from remote.
|
2024-05-05 22:14:55 +02:00
|
|
|
func FetchSource(repo Repository) *types.Cmd {
|
2023-02-08 10:16:10 +01:00
|
|
|
args := []string{
|
2022-12-02 22:21:35 +01:00
|
|
|
"fetch",
|
|
|
|
"origin",
|
|
|
|
fmt.Sprintf("+%s:", repo.Branch),
|
2023-02-08 10:16:10 +01:00
|
|
|
}
|
|
|
|
|
2024-05-05 22:14:55 +02:00
|
|
|
cmd := execabs.Command(gitBin, args...)
|
2022-12-02 22:21:35 +01:00
|
|
|
cmd.Dir = repo.WorkDir
|
|
|
|
|
2024-05-05 22:14:55 +02:00
|
|
|
return &types.Cmd{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2022-12-02 22:21:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutHead handles branch checkout.
|
2024-05-05 22:14:55 +02:00
|
|
|
func CheckoutHead(repo Repository) *types.Cmd {
|
2023-02-08 10:16:10 +01:00
|
|
|
args := []string{
|
2022-12-02 22:21:35 +01:00
|
|
|
"checkout",
|
|
|
|
"-qf",
|
|
|
|
repo.Branch,
|
2023-02-08 10:16:10 +01:00
|
|
|
}
|
|
|
|
|
2024-05-05 22:14:55 +02:00
|
|
|
cmd := execabs.Command(gitBin, args...)
|
2022-12-02 22:21:35 +01:00
|
|
|
cmd.Dir = repo.WorkDir
|
|
|
|
|
2024-05-05 22:14:55 +02:00
|
|
|
return &types.Cmd{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2022-12-02 22:21:35 +01:00
|
|
|
}
|