0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-28 18:20:35 +00:00
wp-git-action/git/remote.go

66 lines
1.1 KiB
Go
Raw Normal View History

2022-11-27 13:33:39 +00:00
package git
2019-06-07 10:32:16 +00:00
import (
"fmt"
"os"
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
2019-06-07 10:32:16 +00:00
)
// RemoteRemove drops the defined remote from a git repo.
func (r *Repository) RemoteRemove() *plugin_exec.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"remote",
"rm",
2024-05-06 18:29:57 +00:00
r.RemoteName,
}
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
2019-06-07 10:32:16 +00:00
2024-05-06 20:43:56 +00:00
return cmd
2019-06-07 10:32:16 +00:00
}
// RemoteAdd adds an additional remote to a git repo.
func (r *Repository) RemoteAdd() *plugin_exec.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"remote",
"add",
2024-05-06 18:29:57 +00:00
r.RemoteName,
r.RemoteURL,
}
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
2019-06-07 10:32:16 +00:00
2024-05-06 20:43:56 +00:00
return cmd
2019-06-07 10:32:16 +00:00
}
2022-11-28 14:36:01 +00:00
// RemotePush pushs the changes from the local head to a remote branch.
func (r *Repository) RemotePush() *plugin_exec.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"push",
2024-05-06 18:29:57 +00:00
r.RemoteName,
fmt.Sprintf("HEAD:%s", r.Branch),
}
2024-05-06 18:29:57 +00:00
if r.ForcePush {
2024-05-06 20:43:56 +00:00
args = append(args, "--force")
2019-06-07 10:32:16 +00:00
}
2024-05-06 18:29:57 +00:00
if r.PushFollowTags {
2024-05-06 20:43:56 +00:00
args = append(args, "--follow-tags")
2019-06-07 10:32:16 +00:00
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
2024-05-06 20:43:56 +00:00
cmd.Dir = r.WorkDir
return cmd
2019-06-07 10:32:16 +00:00
}