wip
This commit is contained in:
parent
6aa53bdf25
commit
73e817d408
@ -40,6 +40,10 @@ type GitSubmoduleLister interface {
|
||||
GitSubmoduleCommitId(cwd, packageName, commitId string) (subCommitId string, valid bool)
|
||||
}
|
||||
|
||||
type GitStatusLister interface {
|
||||
GitStatus(cwd string) ([]GitStatusData, error)
|
||||
}
|
||||
|
||||
type Git interface {
|
||||
GetPath() string
|
||||
|
||||
@ -48,6 +52,7 @@ type Git interface {
|
||||
io.Closer
|
||||
|
||||
GitSubmoduleLister
|
||||
GitStatusLister
|
||||
|
||||
GitExecWithOutputOrPanic(cwd string, params ...string) string
|
||||
GitExecOrPanic(cwd string, params ...string)
|
||||
@ -909,7 +914,7 @@ func parseGitStatusData(data io.ByteReader) ([]GitStatusData, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) Status(cwd string) (ret []GitStatusData, err error) {
|
||||
func (e *GitHandlerImpl) GitStatus(cwd string) (ret []GitStatusData, err error) {
|
||||
if e.DebugLogger {
|
||||
log.Println("getting git-status()")
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func (rs *PRSet) Merge() error {
|
||||
return err
|
||||
}
|
||||
|
||||
gh:=common.GitHandlerGeneratorImpl{}
|
||||
gh := common.GitHandlerGeneratorImpl{}
|
||||
git, err := gh.CreateGitHandler(GitAuthor, GitEmail, prjgit.Base.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -133,18 +133,54 @@ func (rs *PRSet) Merge() error {
|
||||
return fmt.Errorf("Base.Sha (%s) not yet merged into project-git. Aborting merge.", prjgit.Base.Sha)
|
||||
}
|
||||
/*
|
||||
rev := git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "rev-list", "-1", "HEAD")
|
||||
if rev != prjgit.Base.Sha {
|
||||
panic("FIXME")
|
||||
}
|
||||
*/
|
||||
rev := git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "rev-list", "-1", "HEAD")
|
||||
if rev != prjgit.Base.Sha {
|
||||
panic("FIXME")
|
||||
}
|
||||
*/
|
||||
msg := "haha"
|
||||
|
||||
err = git.GitExec(common.DefaultGitPrj, "merge", "--no-ff", "-m", msg, prjgit.Head.Sha)
|
||||
if err != nil {
|
||||
status, statusErr := git.GitStatus(common.DefaultGitPrj)
|
||||
if statusErr != nil {
|
||||
return fmt.Errorf("Failed to merge: %w . Status also failed: %w", err, statusErr)
|
||||
}
|
||||
|
||||
// we can only resolve conflicts with .gitmodules
|
||||
for _, s := range status {
|
||||
if s.Status == common.GitStatus_Unmerged {
|
||||
if s.Path != ".gitmodules" {
|
||||
return err
|
||||
}
|
||||
/*
|
||||
|
||||
submodules, err := git.GitSubmoduleList(common.DefaultGitPrj, "MERGE_HEAD")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to fetch submodules during merge resolution: %w", err)
|
||||
}
|
||||
s1, err := git.GitExecWithOutput(common.DefaultGitPrj, "git", "cat-file", "blob", s.States[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed fetching data during .gitmodules merge resoulution: %w", err)
|
||||
}
|
||||
s2, err := git.GitExecWithOutput(common.DefaultGitPrj, "git", "cat-file", "blob", s.States[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed fetching data during .gitmodules merge resoulution: %w", err)
|
||||
}
|
||||
s3, err := git.GitExecWithOutput(common.DefaultGitPrj, "git", "cat-file", "blob", s.States[2])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed fetching data during .gitmodules merge resoulution: %w", err)
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "Aborting merge") {
|
||||
return errors.New("stuff")
|
||||
}
|
||||
return err
|
||||
}
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "push", "origin")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
57
workflow-pr/submodules_test.go
Normal file
57
workflow-pr/submodules_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSubmodules(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
file string
|
||||
subs []Submodule
|
||||
}{
|
||||
{
|
||||
name: "Empty submodules file",
|
||||
file: "",
|
||||
subs: []Submodule{},
|
||||
},
|
||||
{
|
||||
name: "Simple submodule",
|
||||
file: `[submodule "libfoo"]
|
||||
path = include/foo
|
||||
url = git://foo.com/git/lib.git
|
||||
|
||||
[submodule "libbar"]
|
||||
path = include/bar
|
||||
url = git://bar.com/git/lib.git`,
|
||||
|
||||
subs: []Submodule{
|
||||
{
|
||||
Name: "libfoo",
|
||||
Path: "include/foo",
|
||||
Url: "git://foo.com/git/lib.git",
|
||||
},
|
||||
{
|
||||
Name: "libbar",
|
||||
Path: "include/bar",
|
||||
Url: "git://bar.com/git/lib.git",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
mods, err := ParseSubmodules(strings.NewReader(test.file))
|
||||
if err != nil {
|
||||
t.Error("unexpected error:", err)
|
||||
}
|
||||
if !slices.Equal(mods, test.subs) {
|
||||
t.Error("expected", test.subs, "but got", mods)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user