-
Notifications
You must be signed in to change notification settings - Fork 4
test issue 1 #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test issue 1 #148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2026-present unTill Software Development Group B.V. | ||
| * @author Denis Gribanov | ||
| */ | ||
|
|
||
| package gitcmds | ||
|
|
||
| import "strings" | ||
|
|
||
| // LoadRepoContext gathers repository state needed by Dev() in minimal git round-trips. | ||
| // Phase 1 runs five independent local git commands concurrently. | ||
| // Phase 2 issues one gh API call that requires Org/Repo obtained in phase 1. | ||
| func LoadRepoContext(wd string) (*RepoContext, error) { | ||
| rc := &RepoContext{} | ||
|
|
||
| type result struct { | ||
| setFn func() | ||
| err error | ||
| } | ||
|
|
||
| const numConcurrent = 5 | ||
| ch := make(chan result, numConcurrent) | ||
|
|
||
| go func() { | ||
| v, err := HasRemote(wd, "upstream") | ||
| ch <- result{setFn: func() { rc.UpstreamExists = v }, err: err} | ||
| }() | ||
|
|
||
| go func() { | ||
| repo, org, err := GetRepoAndOrgName(wd) | ||
| ch <- result{setFn: func() { rc.Repo = repo; rc.Org = org }, err: err} | ||
| }() | ||
|
|
||
| go func() { | ||
| v, err := GetCurrentBranchName(wd) | ||
| ch <- result{setFn: func() { rc.CurrentBranch = v }, err: err} | ||
| }() | ||
|
|
||
| go func() { | ||
| v, err := GetMainBranch(wd) | ||
| ch <- result{setFn: func() { rc.MainBranch = v }, err: err} | ||
| }() | ||
|
|
||
| go func() { | ||
| v, err := HaveUncommittedChanges(wd) | ||
| ch <- result{setFn: func() { rc.HasUncommittedChanges = v }, err: err} | ||
| }() | ||
|
|
||
| for range numConcurrent { | ||
| r := <-ch | ||
| if r.err != nil { | ||
| return nil, r.err | ||
| } | ||
| r.setFn() | ||
| } | ||
|
|
||
| rc.IsMain = strings.EqualFold(rc.CurrentBranch, rc.MainBranch) | ||
|
|
||
| // Phase 2: gh API call needs Org/Repo from phase 1 | ||
| parentRepo, err := getParentRepoByOrgRepo(wd, rc.Org, rc.Repo) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| rc.ParentRepo = parentRepo | ||
|
|
||
| return rc, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,13 +479,8 @@ func GetBranchType(wd string) (string, notesPkg.BranchType, error) { | |
| return currentBranchName, GetBranchTypeByName(currentBranchName), nil | ||
| } | ||
|
|
||
| // GetParentRepoName - parent repo of forked | ||
| func GetParentRepoName(wd string) (name string, err error) { | ||
| repo, org, err := GetRepoAndOrgName(wd) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| // getParentRepoByOrgRepo fetches the parent repository full name via the GitHub API. | ||
| func getParentRepoByOrgRepo(wd, org, repo string) (string, error) { | ||
| stdout, stderr, err := new(exec.PipedExec). | ||
| Command("gh", "api", "repos/"+org+slash+repo, "--jq", ".parent.full_name"). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gitcmds/gitcmds.go:485 — Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| WorkingDir(wd). | ||
|
|
@@ -503,6 +498,16 @@ func GetParentRepoName(wd string) (name string, err error) { | |
| return strings.TrimSpace(stdout), nil | ||
| } | ||
|
|
||
| // GetParentRepoName - parent repo of forked | ||
| func GetParentRepoName(wd string) (name string, err error) { | ||
| repo, org, err := GetRepoAndOrgName(wd) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return getParentRepoByOrgRepo(wd, org, repo) | ||
| } | ||
|
|
||
| // IsBranchInMain Is my branch in main org? | ||
| func IsBranchInMain(wd string) (bool, error) { | ||
| repo, org, err := GetRepoAndOrgName(wd) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,9 @@ func getListOfChangedFiles(wd, statusOutput string) ([]fileInfo, error) { | |
| oldSize = newFileSize | ||
| case `??`: | ||
| newFileSize, err2 = getFileSize(wd, name) | ||
| case `AD`: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case `AD`:
// file was added, then removed -> consider it never existed
continueThe AD handling is correct, but the fix is narrow: other valid two-letter codes from If this scenario is reachable in practice, consider handling the worktree-deleted family generically (e.g. any |
||
| // file was added, then removed -> consider it never existed | ||
| continue | ||
| default: | ||
| return nil, fmt.Errorf("unknown file status %s for file %s", statusCode, name) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,46 @@ | ||
| module github.com/untillpro/qs | ||
|
|
||
| go 1.26.0 | ||
| go 1.26.2 | ||
|
|
||
| require ( | ||
| github.com/atotto/clipboard v0.1.4 | ||
| github.com/coreos/go-semver v0.3.1 | ||
| github.com/fatih/color v1.18.0 | ||
| github.com/go-git/go-git/v5 v5.16.5 | ||
| github.com/fatih/color v1.19.0 | ||
| github.com/go-git/go-git/v5 v5.18.0 | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/spf13/cobra v1.10.2 | ||
| github.com/stretchr/testify v1.11.1 | ||
| github.com/untillpro/goutils v0.0.0-20231201170327-3c33c6010100 | ||
| github.com/voedger/voedger v1.202405300917.1 | ||
| golang.org/x/mod v0.33.0 | ||
| golang.org/x/mod v0.35.0 | ||
| ) | ||
|
|
||
| require ( | ||
| dario.cat/mergo v1.0.2 // indirect | ||
| github.com/Microsoft/go-winio v0.6.2 // indirect | ||
| github.com/ProtonMail/go-crypto v1.3.0 // indirect | ||
| github.com/ProtonMail/go-crypto v1.4.1 // indirect | ||
| github.com/cloudflare/circl v1.6.3 // indirect | ||
| github.com/cyphar/filepath-securejoin v0.6.1 // indirect | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/emirpasic/gods v1.18.1 // indirect | ||
| github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | ||
| github.com/go-git/go-billy/v5 v5.7.0 // indirect | ||
| github.com/go-git/go-billy/v5 v5.8.0 // indirect | ||
| github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||
| github.com/kevinburke/ssh_config v1.6.0 // indirect | ||
| github.com/klauspost/cpuid/v2 v2.3.0 // indirect | ||
| github.com/mattn/go-colorable v0.1.14 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/mattn/go-isatty v0.0.21 // indirect | ||
| github.com/pjbgf/sha1cd v0.5.0 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/sergi/go-diff v1.4.0 // indirect | ||
| github.com/skeema/knownhosts v1.3.2 // indirect | ||
| github.com/spf13/pflag v1.0.10 // indirect | ||
| github.com/xanzy/ssh-agent v0.3.3 // indirect | ||
| golang.org/x/crypto v0.48.0 // indirect | ||
| golang.org/x/net v0.50.0 // indirect | ||
| golang.org/x/sys v0.41.0 // indirect | ||
| golang.org/x/crypto v0.50.0 // indirect | ||
| golang.org/x/net v0.53.0 // indirect | ||
| golang.org/x/sys v0.43.0 // indirect | ||
| gopkg.in/warnings.v0 v0.1.2 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buffered channel capacity and the receive-loop count are both hard-coded to
numConcurrent = 5and must match the number of goroutines launched below. If a future change adds a 6th goroutine without bumping this constant, the 6th send blocks forever after the loop has drained the first 5 (goroutine leak). If a goroutine is removed without decrementing it, the main goroutine blocks forever waiting for a result that never arrives (deadlock).Consider building the work list as a
[]func() error(or a slice of result-producing closures) and deriving both the channel capacity and the loop bound fromlen(tasks)so the count cannot drift. Alternatively, usegolang.org/x/sync/errgroupto manage the goroutines and propagate the first error.