0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-09-20 01:12:47 +02:00
wp-git-action/git/remote.go

77 lines
1.1 KiB
Go
Raw Normal View History

2022-11-27 14:33:39 +01:00
package git
2019-06-07 12:32:16 +02:00
import (
"fmt"
"os"
"golang.org/x/sys/execabs"
2019-06-07 12:32:16 +02:00
)
// RemoteRemove drops the defined remote from a git repo.
func RemoteRemove(repo Repository) *execabs.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"remote",
"rm",
repo.RemoteName,
}
cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 12:32:16 +02:00
return cmd
}
// RemoteAdd adds an additional remote to a git repo.
func RemoteAdd(repo Repository) *execabs.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"remote",
"add",
repo.RemoteName,
repo.RemoteURL,
}
cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 12:32:16 +02:00
return cmd
}
2022-11-28 15:36:01 +01:00
// RemotePush pushs the changes from the local head to a remote branch.
func RemotePush(repo Repository) *execabs.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"push",
repo.RemoteName,
fmt.Sprintf("HEAD:%s", repo.Branch),
}
cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 12:32:16 +02:00
if repo.ForcePush {
2019-06-07 12:32:16 +02:00
cmd.Args = append(
cmd.Args,
"--force",
)
2019-06-07 12:32:16 +02:00
}
if repo.PushFollowTags {
2019-06-07 12:32:16 +02:00
cmd.Args = append(
cmd.Args,
"--follow-tags")
}
return cmd
}