return
}
+// Just for fun, stackgit doesn't have a way to set the working directory
+func (r Repo) stgCmd(args ...string) (out []byte, err error) {
+ if r.Path != "" {
+ cwd, err := os.Getwd()
+ if err != nil {
+ return nil, err
+ }
+ defer os.Chdir(cwd)
+
+ os.Chdir(r.Path)
+ }
+ fmt.Println(args)
+ out, err = exec.Command("stg", args...).CombinedOutput()
+ fmt.Println(string(out))
+ return
+}
+
+// Will return false if stg is not installed.
+func (r Repo) IsStg(branch string) (bool) {
+ _, err := r.stgCmd("series", "-b", branch)
+ return err == nil
+}
+
func GitClone(gpath string, origin string) (r Repo, err error) {
if !path.IsAbs(gpath) {
cwd, err := os.Getwd()
// FIXME: Option to fail if it already exists?
func (r Repo) MakeBranch(branch string, ref string) (err error) {
+ // Can't simply reset a stackgit branch, but if we delete the
+ // old one and checkout the new one it's the same effect
+ if r.IsStg(branch) {
+ _, err = r.stgCmd("branch", "--delete", "--force", branch)
+ if err != nil {
+ return
+ }
+ }
_, err = r.gitCmd("checkout", "-B", branch, ref)
if err == nil {
_, err = r.gitCmd("clean", "-ffdx")
return
}
+// These are basically identical now; but I feel like there needs to
+// be a distinction made
+func (r Repo) ResetBranch(branch string, ref string) (err error) {
+ return r.MakeBranch(branch, ref)
+}
+
+
+
func (r Repo) Checkout(branch string) (out []byte, err error) {
out, err = r.gitCmd("checkout", branch)
if err == nil {
}
func (r Repo) DeleteBranch(branch string) (out []byte, err error) {
- out, err = r.gitCmd("branch", "-D", branch)
-
- return
-}
-
-func (r Repo) ResetBranch(branch string, commit string) (out []byte, err error) {
- out, err = r.gitCmd("checkout", "-B", branch, commit)
+ if r.IsStg(branch) {
+ out, err = r.stgCmd("branch", "--delete", "--force", branch)
+ } else {
+ out, err = r.gitCmd("branch", "-D", branch)
+ }
return
}