0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-06-03 04:39:42 +02:00
wp-git-action/git/remote.go

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