summaryrefslogtreecommitdiff
path: root/getPatches.go
blob: ffb135e18340c7a594e8d5f1200d076fd9c0826b (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package repolist

import (
	"path/filepath"
	"strings"

	"go.wit.com/lib/gui/repostatus"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

type Patch struct {
	Ref     string
	giturl  string
	comment string
	RS      *repostatus.RepoStatus
}

/* move all this to repolist and gowit repos
p, allp := s.GetPatches()
if s.allp == nil {
	s.allp = make([]*patch, 0, 0)
	s.allp = append(s.allp, allp...)
}
if dirty == 0 {
	s.totalPatchesOL.SetText(strconv.Itoa(p) + " patches")
	s.reason.Enable()
	// force the user to submit a reason to enable the submit button
	// s.submitB.Enable()
} else {
	s.totalPatchesOL.SetText(strconv.Itoa(p) + " patches + ? dirty")
}
*/

// move all this to repolist and gowit repos

func (repo *Repo) GetPatches(oldname string, newname string) (int, []*Patch) {
	var patchcount int
	patches := make([]*Patch, 0, 0)

	// git log --oneline devel..jcarr
	// userv := repo.Status.GetUserVersion()
	// develv := repo.Status.GetDevelVersion()
	// usern := repo.Status.GetUserBranchName()
	// develn := repo.Status.GetDevelBranchName()
	if oldname == newname {
		return 0, nil
	}
	// log.Info("repo userv, develv", userv, develv)
	gitcmd := []string{"git", "log", "--oneline", oldname + ".." + newname}
	log.Info("Run:", gitcmd)
	err, output := repo.Status.RunCmd(gitcmd)
	if err != nil {
		log.Info("git failed ", repo.GoPath(), "err =", err)
		return 0, nil
	}

	// patches = strings.Split(output, "\n")
	log.Info("Run:", output)
	for _, line := range strings.Split(output, "\n") {
		line = strings.TrimSpace(line)
		if line == "" {
			continue
		}
		parts := strings.Split(line, " ")
		newp := new(Patch)
		newp.RS = repo.Status
		newp.Ref = parts[0]
		newp.comment = strings.Join(parts[1:], " ")
		log.Info("Patch line:", line, newp.RS.String())
		patchcount += 1
		patches = append(patches, newp)
	}
	return patchcount, patches
}

func (repo *Repo) GetUserPatches() (int, []*Patch) {
	usern := repo.Status.GetUserBranchName()
	develn := repo.Status.GetDevelBranchName()
	userv := repo.Status.GetUserVersion()
	develv := repo.Status.GetDevelVersion()

	if userv == develv {
		return 0, nil
	}

	c, all := repo.GetPatches(develn, usern)
	log.Info("GetPatches() guireleaser", develn, usern, "count =", c)
	return c, all
}

func (repo *Repo) GetMasterPatches() (int, []*Patch) {
	lasttag := repo.LastTag()
	mastern := repo.Status.GetMasterBranchName()
	masterv := repo.Status.GetMasterVersion()

	if lasttag == masterv {
		return 0, nil
	}

	c, all := repo.GetPatches(lasttag, mastern)
	log.Info("GetPatches() guireleaser", lasttag, mastern, "count =", c)
	return c, all
}

func (r *RepoList) MakePatchset(setdir string) bool {
	for _, repo := range r.allrepos {
		userv := repo.Status.GetUserVersion()
		develv := repo.Status.GetDevelVersion()
		usern := repo.Status.GetUserBranchName()
		develn := repo.Status.GetDevelBranchName()
		if userv == develv {
			// this repo is unchanged
			continue
		}

		repodir := filepath.Join(setdir, repo.GoPath())
		shell.Mkdir(repodir)
		// git format-patch branch1..branch2
		gitcmd := []string{"git", "format-patch", "-o", repodir, develn + ".." + usern}
		log.Info("Run:", gitcmd)
		err, output := repo.Status.RunCmd(gitcmd)
		log.Info("output =", output)
		if err == nil {
			log.Info("patches made okay for:", repo.GoPath())
			continue
		}
		log.Info("patches failed for:", repo.GoPath())
		return false
	}
	return true
}