Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v1.64
version: v2.12.2

build:
name: Build
Expand Down
622 changes: 226 additions & 396 deletions .golangci.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/golangci/golangci-lint
rev: v1.64.5
rev: v2.12.2
hooks:
- id: golangci-lint-config-verify
entry: go tool golangci-lint config verify
Expand Down
215 changes: 129 additions & 86 deletions go.mod

Large diffs are not rendered by default.

359 changes: 359 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion internal/adapters/primary/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"github.com/spf13/cobra"
)

const cmdNameConfig = "config"

// RegisterConfigCommand registers the config command.
func RegisterConfigCommand(root *cobra.Command) {
configCmd := &cobra.Command{
Use: "config",
Use: cmdNameConfig,
Short: "Configurations",
}

Expand Down
8 changes: 5 additions & 3 deletions internal/adapters/primary/cli/config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"github.com/spf13/cobra"
)

const gitModeNative = "native"

// boolToMode converts boolean to mode string.
func boolToMode(embedded bool) string {
if embedded {
return "embedded"
}

return "native"
return gitModeNative
}

// registryGitCmd registers the git command.
Expand All @@ -29,7 +31,7 @@ func registryGitCmd(root *cobra.Command) {
gitModeCmd := &cobra.Command{
Use: "mode [type]",
Short: "Configure Git mode",
ValidArgs: []string{"native", "embedded", "default"},
ValidArgs: []string{gitModeNative, "embedded", "default"},
Args: func(cmd *cobra.Command, args []string) error {
err := cobra.OnlyValidArgs(cmd, args)
if err == nil {
Expand All @@ -45,7 +47,7 @@ func registryGitCmd(root *cobra.Command) {
return nil
},
Run: func(_ *cobra.Command, args []string) {
env.GlobalConfiguration().GitEmbedded = args[0] != "native"
env.GlobalConfiguration().GitEmbedded = args[0] != gitModeNative

msg.Info("Using %s git", boolToMode(env.GlobalConfiguration().GitEmbedded))
env.GlobalConfiguration().SaveConfiguration()
Expand Down
2 changes: 1 addition & 1 deletion internal/adapters/primary/cli/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func printSingleDependency(

// isOutdated checks if the dependency is outdated.
func isOutdated(dependency domain.Dependency, version string) (dependencyStatus, string) {
if err := installer.GetDependency(dependency); err != nil {
if err := installer.GetDependency(dependency); err != nil { //nolint:staticcheck // TODO: migrate to DependencyManager
return updated, ""
}
cacheService := cache.NewCacheService(filesystem.NewOSFileSystem())
Expand Down
11 changes: 8 additions & 3 deletions internal/adapters/primary/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ import (
"github.com/spf13/cobra"
)

const (
appName = "boss"
appDescription = "Dependency Manager for Delphi"
)

// Execute executes the root command.
func Execute() error {
var versionPrint bool
var global bool
var debug bool

var root = &cobra.Command{
Use: "boss",
Short: "Dependency Manager for Delphi",
Long: "Dependency Manager for Delphi",
Use: appName,
Short: appDescription,
Long: appDescription,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
if debug {
msg.LogLevel(msg.DEBUG)
Expand Down
5 changes: 5 additions & 0 deletions internal/adapters/secondary/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func GetVersions(config env.ConfigProvider, repository *goGit.Repository, dep do
return result
}

// GetTagsShortName returns the short names of all tags in the repository.
func GetTagsShortName(repository *goGit.Repository) []string {
tags, _ := repository.Tags()
var result = []string{}
Expand All @@ -120,6 +121,7 @@ func GetTagsShortName(repository *goGit.Repository) []string {
return result
}

// GetByTag returns the reference matching the given short tag name.
func GetByTag(repository *goGit.Repository, shortName string) *plumbing.Reference {
tags, _ := repository.Tags()

Expand All @@ -134,6 +136,7 @@ func GetByTag(repository *goGit.Repository, shortName string) *plumbing.Referenc
}
}

// GetRepository opens an existing dependency repository from the cache.
func GetRepository(dep domain.Dependency) *goGit.Repository {
// GetRepository is used in places where we already have a cloned repo
// So we don't need config for EnsureCacheDir check
Expand All @@ -147,13 +150,15 @@ func GetRepository(dep domain.Dependency) *goGit.Repository {
return repository
}

// Checkout switches the dependency repository to the given reference.
func Checkout(config env.ConfigProvider, dep domain.Dependency, referenceName plumbing.ReferenceName) error {
if config.GetGitEmbedded() {
return CheckoutEmbedded(config, dep, referenceName)
}
return CheckoutNative(dep, referenceName)
}

// Pull fetches and merges updates for the dependency repository.
func Pull(config env.ConfigProvider, dep domain.Dependency) error {
if config.GetGitEmbedded() {
return PullEmbedded(config, dep)
Expand Down
2 changes: 2 additions & 0 deletions internal/adapters/secondary/git/git_embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func createWorktreeFs(config env.ConfigProvider, dep domain.Dependency) billy.Fi
return fs
}

// CheckoutEmbedded switches the dependency repository to the given reference using go-git.
func CheckoutEmbedded(_ env.ConfigProvider, dep domain.Dependency, referenceName plumbing.ReferenceName) error {
repository := GetRepository(dep)
worktree, err := repository.Worktree()
Expand All @@ -123,6 +124,7 @@ func CheckoutEmbedded(_ env.ConfigProvider, dep domain.Dependency, referenceName
})
}

// PullEmbedded fetches and merges updates using go-git.
func PullEmbedded(config env.ConfigProvider, dep domain.Dependency) error {
repository := GetRepository(dep)
worktree, err := repository.Worktree()
Expand Down
19 changes: 11 additions & 8 deletions internal/adapters/secondary/git/git_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package gitadapter

import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
Expand All @@ -17,7 +18,7 @@ import (
)

func checkHasGitClient() {
command := exec.Command("where", "git")
command := exec.CommandContext(context.Background(), "where", "git")
_, err := command.Output()
if err != nil {
msg.Die("❌ 'git.exe' not found in path")
Expand Down Expand Up @@ -66,7 +67,7 @@ func doClone(dep domain.Dependency) error {
args = append(args, dep.GetURL(), dirModule)

//nolint:gosec,nolintlint // Git command with controlled and validated repository URL
cmd := exec.Command("git", args...) // #nosec G204 -- Controlled git clone command
cmd := exec.CommandContext(context.Background(), "git", args...) // #nosec G204 -- Controlled git clone command

if err = runCommand(cmd); err != nil {
return err
Expand Down Expand Up @@ -98,13 +99,13 @@ func getWrapperFetch(dep domain.Dependency) error {
}

writeDotGitFile(dep)
cmdReset := exec.Command("git", "reset", "--hard")
cmdReset := exec.CommandContext(context.Background(), "git", "reset", "--hard")
cmdReset.Dir = dirModule
if err := runCommand(cmdReset); err != nil {
return err
}

cmd := exec.Command("git", "fetch", "--all")
cmd := exec.CommandContext(context.Background(), "git", "fetch", "--all")
cmd.Dir = dirModule

if err := runCommand(cmd); err != nil {
Expand All @@ -121,7 +122,7 @@ func getWrapperFetch(dep domain.Dependency) error {

func initSubmodulesNative(dep domain.Dependency) error {
dirModule := filepath.Join(env.GetModulesDir(), dep.Name())
cmd := exec.Command("git", "submodule", "update", "--init", "--recursive")
cmd := exec.CommandContext(context.Background(), "git", "submodule", "update", "--init", "--recursive")
cmd.Dir = dirModule

if err := runCommand(cmd); err != nil {
Expand All @@ -130,17 +131,19 @@ func initSubmodulesNative(dep domain.Dependency) error {
return nil
}

// CheckoutNative switches the dependency repository to the given reference using system git.
func CheckoutNative(dep domain.Dependency, referenceName plumbing.ReferenceName) error {
dirModule := filepath.Join(env.GetModulesDir(), dep.Name())
//nolint:gosec,nolintlint // Git command with controlled repository reference
cmd := exec.Command("git", "checkout", "-f", referenceName.Short()) // #nosec G204 -- Controlled git checkout command
cmd := exec.CommandContext(context.Background(),
"git", "checkout", "-f", referenceName.Short()) // #nosec G204 -- Controlled git checkout command
cmd.Dir = dirModule
return runCommand(cmd)
}

// PullNative fetches and merges updates using system git.
func PullNative(dep domain.Dependency) error {
dirModule := filepath.Join(env.GetModulesDir(), dep.Name())
cmd := exec.Command("git", "pull", "--force")
cmd := exec.CommandContext(context.Background(), "git", "pull", "--force")
cmd.Dir = dirModule
return runCommand(cmd)
}
Expand Down
28 changes: 12 additions & 16 deletions internal/core/domain/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ func (g *GraphItem) String() {

for index := range g.nodes {
var node = g.nodes[index]
var response = ""
response += g.nodes[index].String() + " -> \n\t\tDepends: "
var response strings.Builder
response.WriteString(g.nodes[index].String())
response.WriteString(" -> \n\t\tDepends: ")
nears := g.depends[node.Value]
for _, near := range nears {
response += near.String() + " - "
response.WriteString(near.String())
response.WriteString(" - ")
}

response += "\n\t\tUsed by: "
response.WriteString("\n\t\tUsed by: ")
nears = g.usedBy[node.Value]
for _, near := range nears {
response += near.String() + " - "
response.WriteString(near.String())
response.WriteString(" - ")
}
msg.Info(response)
msg.Info(response.String())
}
g.unlock()
}
Expand Down Expand Up @@ -147,11 +150,7 @@ func (g *GraphItem) Queue(pkg *Package, allDeps bool) *NodeQueue {
}

func (g *GraphItem) processNodes(nodes []*Node, queue *NodeQueue) {
for {
if len(nodes) == 0 {
break
}

for len(nodes) > 0 {
for key := 0; key < len(nodes); key++ {
node := nodes[key]
if !containsOne(g.depends[node.Value], nodes) {
Expand All @@ -164,11 +163,8 @@ func (g *GraphItem) processNodes(nodes []*Node, queue *NodeQueue) {
}

func (g *GraphItem) expandGraphNodes(nodes []*Node, pkg *Package) []*Node {
var redo = true
for {
if !redo {
break
}
redo := true
for redo {
redo = false
for _, node := range nodes {
usedBy := g.usedBy[node.Value]
Expand Down
1 change: 1 addition & 0 deletions internal/core/ports/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Branch interface {
}

// GitClient is a simplified interface for git operations without mandatory context.
//
// Deprecated: New code should use GitRepository which supports context.
type GitClient interface {
// CloneCache clones a dependency repository to cache.
Expand Down
13 changes: 6 additions & 7 deletions internal/core/services/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ func Build(pkg *domain.Package, compilerVersion, platform string) {
}

func saveLoadOrder(queue *domain.NodeQueue) error {
var projects = ""
for {
if queue.IsEmpty() {
break
}
var projects strings.Builder
for !queue.IsEmpty() {
node := queue.Dequeue()
dependencyPath := filepath.Join(env.GetModulesDir(), node.Dep.Name(), consts.FilePackage)
if dependencyPackage, err := pkgmanager.LoadPackageOther(dependencyPath); err == nil {
for _, value := range dependencyPackage.Projects {
projects += strings.TrimSuffix(filepath.Base(value), filepath.Ext(value)) + consts.FileExtensionBpl + "\n"
projects.WriteString(strings.TrimSuffix(filepath.Base(value), filepath.Ext(value)))
projects.WriteString(consts.FileExtensionBpl)
projects.WriteString("\n")
}
}
}
outDir := filepath.Join(env.GetModulesDir(), consts.BplFolder, consts.FileBplOrder)

if err := os.WriteFile(outDir, []byte(projects), 0600); err != nil {
if err := os.WriteFile(outDir, []byte(projects.String()), 0600); err != nil {
return fmt.Errorf("failed to save build load order to %s: %w", outDir, err)
}
return nil
Expand Down
Loading
Loading