go-devops/cmd/dev/cmd_pull.go

131 lines
2.9 KiB
Go
Raw Normal View History

package dev
import (
"context"
"os/exec"
fix(devops): r2 — replace must* helpers with stdlib + verify CLI module resolution on PR #2 Round 2 follow-up to 907c5fa. Closes residual CodeRabbit findings. Test infra: - Replaced must* test helpers across cmd_apply_test, cmd_file_sync_test, cmd_vm_test, cmd_ci_test, cmd_repo_test, cmd_wizard_test, cmd_api_testgen_test, cmd_workflow_test, secret_test, coverage_test, scan_secrets_test, snapshot_test with stdlib checks. - Deleted stale package-level test_helpers_test.go files that only supported the old must* pattern. - AX-6 maintained: no testify Go imports / go.mod requires. Remaining go.sum testify entries are transitive checksums after go mod tidy. Module graph: - CLI imports switched back to Cobra-compatible dappco.re/go/core/cli/pkg/cli module + replacements for private vanity modules. GOWORK=off resolves cleanly under isolated cache. - locales/embed.go / go.sum: i18n checksum + go mod tidy clean. Verified-but-already-correct (no code change needed): - cmd/dev/service.go: no-op core.Result{OK:true} + prompt type assertion - cmd/workspace/config.go: filepath.Abs normalisation + fmt.Errorf wrapping - tests/cli/devops/main.go: raw walk/read errors wrapped - tests/cli/devops/Taskfile.yaml: strict shell flags - cmd/dev/cmd_issues.go + cmd_reviews.go: import grouping (after CLI module correction) Verification: gofmt clean, GOWORK=off go vet + go test -count=1 ./... pass with explicit cache paths. Closes residual findings on https://github.com/dAppCore/go-devops/pull/2 Co-authored-by: Codex <noreply@openai.com>
2026-04-27 17:29:14 +01:00
"dappco.re/go/core/cli/pkg/cli"
"dappco.re/go/i18n"
fix(devops): r2 — replace must* helpers with stdlib + verify CLI module resolution on PR #2 Round 2 follow-up to 907c5fa. Closes residual CodeRabbit findings. Test infra: - Replaced must* test helpers across cmd_apply_test, cmd_file_sync_test, cmd_vm_test, cmd_ci_test, cmd_repo_test, cmd_wizard_test, cmd_api_testgen_test, cmd_workflow_test, secret_test, coverage_test, scan_secrets_test, snapshot_test with stdlib checks. - Deleted stale package-level test_helpers_test.go files that only supported the old must* pattern. - AX-6 maintained: no testify Go imports / go.mod requires. Remaining go.sum testify entries are transitive checksums after go mod tidy. Module graph: - CLI imports switched back to Cobra-compatible dappco.re/go/core/cli/pkg/cli module + replacements for private vanity modules. GOWORK=off resolves cleanly under isolated cache. - locales/embed.go / go.sum: i18n checksum + go mod tidy clean. Verified-but-already-correct (no code change needed): - cmd/dev/service.go: no-op core.Result{OK:true} + prompt type assertion - cmd/workspace/config.go: filepath.Abs normalisation + fmt.Errorf wrapping - tests/cli/devops/main.go: raw walk/read errors wrapped - tests/cli/devops/Taskfile.yaml: strict shell flags - cmd/dev/cmd_issues.go + cmd_reviews.go: import grouping (after CLI module correction) Verification: gofmt clean, GOWORK=off go vet + go test -count=1 ./... pass with explicit cache paths. Closes residual findings on https://github.com/dAppCore/go-devops/pull/2 Co-authored-by: Codex <noreply@openai.com>
2026-04-27 17:29:14 +01:00
"dappco.re/go/scm/git"
)
// Pull command flags
var (
pullRegistryPath string
pullAll bool
)
// AddPullCommand adds the 'pull' command to the given parent command.
func AddPullCommand(parent *cli.Command) {
pullCmd := &cli.Command{
Use: "pull",
Short: i18n.T("cmd.dev.pull.short"),
Long: i18n.T("cmd.dev.pull.long"),
RunE: func(cmd *cli.Command, args []string) error {
return runPull(pullRegistryPath, pullAll)
},
}
pullCmd.Flags().StringVar(&pullRegistryPath, "registry", "", i18n.T("common.flag.registry"))
pullCmd.Flags().BoolVar(&pullAll, "all", false, i18n.T("cmd.dev.pull.flag.all"))
parent.AddCommand(pullCmd)
}
func runPull(registryPath string, all bool) error {
ctx := context.Background()
// Find or use provided registry
reg, _, err := loadRegistryWithConfig(registryPath)
if err != nil {
return err
}
// Build paths and names for git operations
var paths []string
names := make(map[string]string)
for _, repo := range reg.List() {
if repo.IsGitRepo() {
paths = append(paths, repo.Path)
names[repo.Path] = repo.Name
}
}
if len(paths) == 0 {
cli.Text(i18n.T("cmd.dev.no_git_repos"))
return nil
}
// Get status for all repos
statuses := git.Status(ctx, git.StatusOptions{
Paths: paths,
Names: names,
})
// Find repos to pull
var toPull []git.RepoStatus
for _, s := range statuses {
if s.Error != nil {
continue
}
if all || s.HasUnpulled() {
toPull = append(toPull, s)
}
}
if len(toPull) == 0 {
cli.Text(i18n.T("cmd.dev.pull.all_up_to_date"))
return nil
}
// Show what we're pulling
if all {
cli.Print("\n%s\n\n", i18n.T("cmd.dev.pull.pulling_repos", map[string]any{"Count": len(toPull)}))
} else {
cli.Print("\n%s\n\n", i18n.T("cmd.dev.pull.repos_behind", map[string]any{"Count": len(toPull)}))
for _, s := range toPull {
cli.Print(" %s: %s\n",
repoNameStyle.Render(s.Name),
dimStyle.Render(i18n.T("cmd.dev.pull.commits_behind", map[string]any{"Count": s.Behind})),
)
}
cli.Blank()
}
// Pull each repo
var succeeded, failed int
for _, s := range toPull {
cli.Print(" %s %s... ", dimStyle.Render(i18n.T("cmd.dev.pull.pulling")), s.Name)
err := gitPull(ctx, s.Path)
if err != nil {
cli.Print("%s\n", errorStyle.Render("x "+err.Error()))
failed++
} else {
cli.Print("%s\n", successStyle.Render("v"))
succeeded++
}
}
// Summary
cli.Blank()
cli.Print("%s", successStyle.Render(i18n.T("cmd.dev.pull.done_pulled", map[string]any{"Count": succeeded})))
if failed > 0 {
cli.Print(", %s", errorStyle.Render(i18n.T("common.count.failed", map[string]any{"Count": failed})))
}
cli.Blank()
return nil
}
func gitPull(ctx context.Context, path string) error {
cmd := exec.CommandContext(ctx, "git", "pull", "--ff-only")
cmd.Dir = path
output, err := cmd.CombinedOutput()
if err != nil {
return cli.Err("%s", string(output))
}
return nil
}