summaryrefslogtreecommitdiff
path: root/branches.go
diff options
context:
space:
mode:
Diffstat (limited to 'branches.go')
-rw-r--r--branches.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/branches.go b/branches.go
index 192e4e3..46ea091 100644
--- a/branches.go
+++ b/branches.go
@@ -2,6 +2,7 @@ package gitpb
import (
"errors"
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -10,18 +11,6 @@ import (
)
// returns true if 'git pull' will work
-func (repo *Repo) IsBranchRemote(branchname string) bool {
- if branchname == "" {
- return false
- }
- if repo.Exists(filepath.Join(".git/refs/remotes/origin", branchname)) {
- // todo: actually use .git/config
- return true
- }
- return false
-}
-
-// returns true if 'git pull' will work
func (repo *Repo) ExistsUserBranchRemote() bool {
branchname := repo.GetUserBranchName()
if repo.IsBranchRemote(branchname) {
@@ -40,11 +29,7 @@ func (repo *Repo) ExistsUserBranch() bool {
// todo: actually use .git/config
return true
}
- if repo.Exists(filepath.Join(".git/refs/remote/origin", branchname)) {
- // todo: actually use .git/config
- return true
- }
- return false
+ return repo.IsBranchRemote(branchname)
}
// returns true if the devel branch exists
@@ -57,11 +42,7 @@ func (repo *Repo) ExistsDevelBranch() bool {
// todo: actually use .git/config
return true
}
- if repo.Exists(filepath.Join(".git/refs/remote/origin", branchname)) {
- // todo: actually use .git/config
- return true
- }
- return false
+ return repo.IsBranchRemote(branchname)
}
func (repo *Repo) GetBranchHash(branchname string) string {
@@ -146,3 +127,22 @@ func (repo *Repo) GetTagHash(t string) string {
return result.Stdout[0]
}
+
+// deletes the devel local branch if it is a subset of the remote devel branch
+func (repo *Repo) DeleteLocalDevelBranch() error {
+ branch := repo.GetDevelBranchName()
+ remote := filepath.Join("origin", branch)
+
+ if !repo.IsDevelRemote() {
+ return fmt.Errorf("no remote branch")
+ }
+ b1 := repo.CountDiffObjects(branch, remote) // should be zero
+ if b1 == 0 {
+ cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
+ log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd)
+ err := repo.RunVerbose(cmd)
+ return err
+ } else {
+ return fmt.Errorf("local branch has patches not in remote")
+ }
+}