9a5720e8ad
Universal: PR Check / Build RC Package (pull_request) Blocked by required conditions
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
2.1 KiB
Go
59 lines
2.1 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"fmt"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/git/gitcmd"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/log"
|
|
)
|
|
|
|
type TemplateSubmoduleCommit struct {
|
|
Path string
|
|
Commit string
|
|
}
|
|
|
|
// GetTemplateSubmoduleCommits returns a list of submodules paths and their commits from a repository
|
|
// This function is only for generating new repos based on existing template, the template couldn't be too large.
|
|
func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits []TemplateSubmoduleCommit, _ error) {
|
|
cmd := gitcmd.NewCommand("ls-tree", "-r", "--", "HEAD")
|
|
stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
|
|
defer stdoutReaderClose()
|
|
err := cmd.WithDir(repoPath).
|
|
WithPipelineFunc(func(ctx gitcmd.Context) error {
|
|
scanner := bufio.NewScanner(stdoutReader)
|
|
for scanner.Scan() {
|
|
entry, err := parseLsTreeLine(scanner.Bytes())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if entry.EntryMode == EntryModeCommit {
|
|
submoduleCommits = append(submoduleCommits, TemplateSubmoduleCommit{Path: entry.Name, Commit: entry.ID.String()})
|
|
}
|
|
}
|
|
return scanner.Err()
|
|
}).
|
|
Run(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("GetTemplateSubmoduleCommits: error running git ls-tree: %v", err)
|
|
}
|
|
return submoduleCommits, nil
|
|
}
|
|
|
|
// AddTemplateSubmoduleIndexes Adds the given submodules to the git index.
|
|
// It is only for generating new repos based on existing template, requires the .gitmodules file to be already present in the work dir.
|
|
func AddTemplateSubmoduleIndexes(ctx context.Context, repoPath string, submodules []TemplateSubmoduleCommit) error {
|
|
for _, submodule := range submodules {
|
|
cmd := gitcmd.NewCommand("update-index", "--add", "--cacheinfo", "160000").AddDynamicArguments(submodule.Commit, submodule.Path)
|
|
if stdout, _, err := cmd.WithDir(repoPath).RunStdString(ctx); err != nil {
|
|
log.Error("Unable to add %s as submodule to repo %s: stdout %s\nError: %v", submodule.Path, repoPath, stdout, err)
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|