2022-12-02 21:21:35 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-02-08 09:16:10 +00:00
|
|
|
|
|
|
|
"golang.org/x/sys/execabs"
|
2022-12-02 21:21:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FetchSource fetches the source from remote.
|
2023-02-08 09:16:10 +00:00
|
|
|
func FetchSource(repo Repository) *execabs.Cmd {
|
|
|
|
args := []string{
|
2022-12-02 21:21:35 +00:00
|
|
|
"fetch",
|
|
|
|
"origin",
|
|
|
|
fmt.Sprintf("+%s:", repo.Branch),
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := execabs.Command(
|
|
|
|
gitBin,
|
|
|
|
args...,
|
2022-12-02 21:21:35 +00:00
|
|
|
)
|
|
|
|
cmd.Dir = repo.WorkDir
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutHead handles branch checkout.
|
2023-02-08 09:16:10 +00:00
|
|
|
func CheckoutHead(repo Repository) *execabs.Cmd {
|
|
|
|
args := []string{
|
2022-12-02 21:21:35 +00:00
|
|
|
"checkout",
|
|
|
|
"-qf",
|
|
|
|
repo.Branch,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := execabs.Command(
|
|
|
|
gitBin,
|
|
|
|
args...,
|
2022-12-02 21:21:35 +00:00
|
|
|
)
|
|
|
|
cmd.Dir = repo.WorkDir
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|