1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package gitpb
import (
"fmt"
"path/filepath"
)
/*
func (repo *Repo) DeleteLocalTag(t *GitTag) bool {
b1, err := repo.CountDiffObjects(branch, remote) // should be zero
if err != nil {
return err
}
if b1 == 0 {
cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
_, err := repo.RunVerboseOnError(cmd)
return err
} else {
return fmt.Errorf("local branch has patches not in remote")
}
}
*/
// deletes the devel local branch if it is a subset of the remote devel branch
func (repo *Repo) DeleteLocalBranch(branch string) ([]string, error) {
remote := filepath.Join("origin", branch)
if !repo.IsBranchRemote(branch) {
return nil, fmt.Errorf("no remote branch")
}
b1, _, err := repo.CountDiffObjectsNEWNEW(branch, remote) // should be zero
if err != nil {
return nil, err
}
if len(b1) == 0 {
// log.Info("SAFE TO DELETE?")
/*
cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
_, err := repo.RunVerboseOnError(cmd)
*/
return nil, nil
}
// log.Info("LOCAL NOT SAFE TO DELETE", repo.FullPath)
return b1, fmt.Errorf("local branch has patches not in remote")
}
// 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, err := repo.CountDiffObjects(branch, remote) // should be zero
if err != nil {
return err
}
if b1 == 0 {
cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
_, err := repo.RunVerboseOnError(cmd)
return err
} else {
return fmt.Errorf("local branch has patches not in remote")
}
}
|