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)
|
GitSubmoduleCommitId(cwd, packageName, commitId string) (subCommitId string, valid bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GitStatusLister interface {
|
||||||
|
GitStatus(cwd string) ([]GitStatusData, error)
|
||||||
|
}
|
||||||
|
|
||||||
type Git interface {
|
type Git interface {
|
||||||
GetPath() string
|
GetPath() string
|
||||||
|
|
||||||
@ -48,6 +52,7 @@ type Git interface {
|
|||||||
io.Closer
|
io.Closer
|
||||||
|
|
||||||
GitSubmoduleLister
|
GitSubmoduleLister
|
||||||
|
GitStatusLister
|
||||||
|
|
||||||
GitExecWithOutputOrPanic(cwd string, params ...string) string
|
GitExecWithOutputOrPanic(cwd string, params ...string) string
|
||||||
GitExecOrPanic(cwd string, params ...string)
|
GitExecOrPanic(cwd string, params ...string)
|
||||||
@ -909,7 +914,7 @@ func parseGitStatusData(data io.ByteReader) ([]GitStatusData, error) {
|
|||||||
return ret, nil
|
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 {
|
if e.DebugLogger {
|
||||||
log.Println("getting git-status()")
|
log.Println("getting git-status()")
|
||||||
}
|
}
|
||||||
|
@ -142,9 +142,45 @@ func (rs *PRSet) Merge() error {
|
|||||||
|
|
||||||
err = git.GitExec(common.DefaultGitPrj, "merge", "--no-ff", "-m", msg, prjgit.Head.Sha)
|
err = git.GitExec(common.DefaultGitPrj, "merge", "--no-ff", "-m", msg, prjgit.Head.Sha)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
git.GitExecOrPanic(common.DefaultGitPrj, "push", "origin")
|
git.GitExecOrPanic(common.DefaultGitPrj, "push", "origin")
|
||||||
return nil
|
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