2022-11-27 13:33:39 +00:00
|
|
|
package git
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RemoteRemove drops the defined remote from a git repo.
|
|
|
|
func RemoteRemove(name string) *exec.Cmd {
|
|
|
|
cmd := exec.Command(
|
|
|
|
"git",
|
|
|
|
"remote",
|
|
|
|
"rm",
|
|
|
|
name)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoteAdd adds an additional remote to a git repo.
|
|
|
|
func RemoteAdd(name, url string) *exec.Cmd {
|
|
|
|
cmd := exec.Command(
|
|
|
|
"git",
|
|
|
|
"remote",
|
|
|
|
"add",
|
|
|
|
name,
|
|
|
|
url)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemotePush pushs the changes from the local head to a remote branch..
|
2022-11-27 13:33:39 +00:00
|
|
|
func RemotePush(remote, branch string, force, followtags bool) *exec.Cmd {
|
2019-06-07 10:32:16 +00:00
|
|
|
return RemotePushNamedBranch(remote, "HEAD", branch, force, followtags)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemotePushNamedBranch puchs changes from a local to a remote branch.
|
2022-11-27 13:33:39 +00:00
|
|
|
func RemotePushNamedBranch(remote, localbranch, branch string, force, followtags bool) *exec.Cmd {
|
2019-06-07 10:32:16 +00:00
|
|
|
cmd := exec.Command(
|
|
|
|
"git",
|
|
|
|
"push",
|
|
|
|
remote,
|
|
|
|
localbranch+":"+branch)
|
|
|
|
|
|
|
|
if force {
|
|
|
|
cmd.Args = append(
|
|
|
|
cmd.Args,
|
|
|
|
"--force")
|
|
|
|
}
|
|
|
|
|
|
|
|
if followtags {
|
|
|
|
cmd.Args = append(
|
|
|
|
cmd.Args,
|
|
|
|
"--follow-tags")
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|