2022-11-27 13:33:39 +00:00
|
|
|
package git
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
import (
|
2022-12-02 21:21:35 +00:00
|
|
|
"fmt"
|
2024-05-17 19:49:59 +00:00
|
|
|
"os"
|
2023-02-08 09:16:10 +00:00
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
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.
|
2024-05-17 19:49:59 +00:00
|
|
|
func (r *Repository) RemoteRemove() *plugin_exec.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2019-06-07 10:32:16 +00:00
|
|
|
"remote",
|
|
|
|
"rm",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.RemoteName,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
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.
|
2024-05-17 19:49:59 +00:00
|
|
|
func (r *Repository) RemoteAdd() *plugin_exec.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2019-06-07 10:32:16 +00:00
|
|
|
"remote",
|
|
|
|
"add",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.RemoteName,
|
|
|
|
r.RemoteURL,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
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.
|
2024-05-17 19:49:59 +00:00
|
|
|
func (r *Repository) RemotePush() *plugin_exec.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
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),
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-05-17 19:49:59 +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
|
|
|
}
|