summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--branches.go44
-rw-r--r--gitTag.common.go21
2 files changed, 41 insertions, 24 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")
+ }
+}
diff --git a/gitTag.common.go b/gitTag.common.go
index a4c7696..d349dea 100644
--- a/gitTag.common.go
+++ b/gitTag.common.go
@@ -21,6 +21,23 @@ func (repo *Repo) DevelHash() string {
return ""
}
+// this is the correct way. uses 'git show-ref'
+func (repo *Repo) IsBranchRemote(brname string) bool {
+ if repo.Tags == nil {
+ return false
+ }
+
+ brname = "refs/remotes/origin/" + brname
+ ref := repo.Tags.FindByRefname(brname)
+ if ref == nil {
+ // log.Info("did not found refname!!!!!!!!", brname)
+ return false
+ }
+ // log.Info("found refname!!!!!!!!")
+ return true
+}
+
+// this is the correct way. uses 'git show-ref'
func (repo *Repo) IsDevelRemote() bool {
if repo.Tags == nil {
return false
@@ -30,10 +47,10 @@ func (repo *Repo) IsDevelRemote() bool {
refname := "refs/remotes/origin/" + devname
ref := repo.Tags.FindByRefname(refname)
if ref == nil {
- log.Info("did not found refname!!!!!!!!", refname)
+ // log.Info("did not found refname!!!!!!!!", refname)
return false
}
- log.Info("found refname!!!!!!!!")
+ // log.Info("found refname!!!!!!!!")
return true
}