wip links

This commit is contained in:
2025-03-13 18:44:38 +01:00
parent bbb721c6fa
commit 1ce38c9de2
2 changed files with 48 additions and 16 deletions

View File

@@ -238,18 +238,24 @@ func verifyProjectState(git common.Git, org string, config *common.AutogitConfig
if _, err := fs.Stat(os.DirFS(git.GetPath()), config.GitProjectName); errors.Is(err, os.ErrNotExist) {
common.PanicOnError(git.GitExec("", "clone", "--depth", "1", repo.SSHURL, config.GitProjectName))
}
log.Println("getting submodule list")
log.Println(" * Getting submodule list")
sub, err := git.GitSubmoduleList(config.GitProjectName, "HEAD")
common.PanicOnError(err)
log.Println(" * Getting package links")
var pkgLinks []*PackageRebaseLink
if f, err := fs.Stat(os.DirFS(path.Join(git.GetPath(), config.GitProjectName)), common.PrjLinksFile); err == nil && (f.Mode()&fs.ModeType == 0) && f.Size() < 1000000 {
if data, err := os.ReadFile(path.Join(git.GetPath(), config.GitProjectName, common.PrjLinksFile)); err != nil {
if data, err := os.ReadFile(path.Join(git.GetPath(), config.GitProjectName, common.PrjLinksFile)); err == nil {
pkgLinks, err = parseProjectLinks(data)
log.Println("Cannot parse project links file: %s", err.Error())
if err != nil {
log.Println("Cannot parse project links file: %s", err.Error())
pkgLinks = nil
} else {
ResolveLinks(org, pkgLinks, gitea)
}
}
} else {
log.Println("No package links defined")
log.Println(" - No package links defined")
}
/* Check existing submodule that they are updated */
@@ -292,20 +298,40 @@ next_package:
for _, l := range pkgLinks {
if l.Pkg == filename {
link = l
log.Println(" -> linked package")
// so, we need to rebase here. Can't really optimize, so clone entire package tree and remote
pkgPath := path.Join(config.GitProjectName, filename)
git.GitExecOrPanic(config.GitProjectName, "submodule", "update", "--init", "--checkout", filename)
git.GitExecOrPanic(pkgPath, "fetch", "origin", commits[0].SHA)
git.GitExecOrPanic(pkgPath, "tag", "NOW")
git.GitExecOrPanic(pkgPath, "fetch", "origin")
git.GitExecOrPanic(pkgPath, "remote", "add", "parent", link.parentRepo.SSHURL)
git.GitExecOrPanic(pkgPath, "fetch", "parent")
git.GitExecOrPanic(pkgPath, "rebase", "--onto", "parent", link.SourceBranch)
nCommits := len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgPath, "rev-list", "^NOW", "HEAD"), "\n"))
if nCommits > 0 {
git.GitExecOrPanic(pkgPath, "push", "-f", "origin", "HEAD:"+config.Branch)
}
break
}
}
if idx == 0 {
// up-to-date
continue
} else if idx < len(commits) { // update
common.PanicOnError(git.GitExec(config.GitProjectName, "submodule", "update", "--init", "--depth", "1", "--checkout", filename))
common.PanicOnError(git.GitExec(filepath.Join(config.GitProjectName, filename), "fetch", "--depth", "1", "origin", commits[0].SHA))
common.PanicOnError(git.GitExec(filepath.Join(config.GitProjectName, filename), "checkout", commits[0].SHA))
isGitUpdated = true
} else {
// probably need `merge-base` or `rev-list` here instead, or the project updated already
return fmt.Errorf("Cannot find SHA of last matching update for package: '%s'. idx: %d", filename, idx)
if link == nil {
if idx == 0 {
// up-to-date
continue
} else if idx < len(commits) { // update
common.PanicOnError(git.GitExec(config.GitProjectName, "submodule", "update", "--init", "--depth", "1", "--checkout", filename))
common.PanicOnError(git.GitExec(filepath.Join(config.GitProjectName, filename), "fetch", "--depth", "1", "origin", commits[0].SHA))
common.PanicOnError(git.GitExec(filepath.Join(config.GitProjectName, filename), "checkout", commits[0].SHA))
isGitUpdated = true
} else {
// probably need `merge-base` or `rev-list` here instead, or the project updated already
return fmt.Errorf("Cannot find SHA of last matching update for package: '%s'. idx: %d", filename, idx)
}
}
}