-
Notifications
You must be signed in to change notification settings - Fork 4
test issue 2 #149
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 2 #149
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) { | ||
|
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:483 — Severity: high 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| stdout, stderr, err := new(exec.PipedExec). | ||
| Command("gh", "api", "repos/"+org+slash+repo, "--jq", ".parent.full_name"). | ||
| 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. gitcmds/status.go:168 — Porcelain status Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| // 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 | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,14 +19,14 @@ import ( | |
| ) | ||
|
|
||
| func Dev(cmd *cobra.Command, wd string, doDelete bool, ignoreHook bool, args []string) error { | ||
| parentRepo, err := gitcmds.GetParentRepoName(wd) | ||
| rc, err := gitcmds.LoadRepoContext(wd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // qs dev -d is running | ||
| if doDelete { | ||
| return deleteBranches(wd, parentRepo) | ||
| return deleteBranches(wd, rc.ParentRepo) | ||
| } | ||
| // qs dev is running | ||
| var devBranchName string | ||
|
|
@@ -42,56 +42,34 @@ func Dev(cmd *cobra.Command, wd string, doDelete bool, ignoreHook bool, args []s | |
| // - If parentRepo exists OR upstream remote exists -> fork workflow | ||
| // - If no parentRepo AND no upstream remote -> single remote workflow | ||
| // Check if upstream remote exists | ||
|
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. Minor: stale comment. The actual |
||
| upstreamExists, err := gitcmds.HasRemote(wd, "upstream") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Only require fork if: | ||
| // 1. No parent repo exists (not a fork), AND | ||
| // 2. Upstream remote exists (indicating fork workflow was intended) | ||
| // This catches the edge case where someone manually added upstream but didn't fork | ||
| if len(parentRepo) == 0 && upstreamExists { | ||
| repo, org, err := gitcmds.GetRepoAndOrgName(wd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return fmt.Errorf("you are in %s/%s repo with upstream remote but no fork detected\nExecute 'qs fork' first", org, repo) | ||
| if len(rc.ParentRepo) == 0 && rc.UpstreamExists { | ||
| return fmt.Errorf("you are in %s/%s repo with upstream remote but no fork detected\nExecute 'qs fork' first", rc.Org, rc.Repo) | ||
| } | ||
|
|
||
| curBranch, mainBranch, isMain, err := gitcmds.GetCurrentBranchInfo(wd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !isMain { | ||
| if !rc.IsMain { | ||
| fmt.Println("--------------------------------------------------------") | ||
| fmt.Println("You are in") | ||
| repo, org, err := gitcmds.GetRepoAndOrgName(wd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| color.New(color.FgHiCyan).Println(org + "/" + repo + "/" + curBranch) | ||
| color.New(color.FgHiCyan).Println(rc.Org + "/" + rc.Repo + "/" + rc.CurrentBranch) | ||
|
|
||
| return fmt.Errorf("switch to main branch before running 'qs dev'. You are in %s branch ", curBranch) | ||
| return fmt.Errorf("switch to main branch before running 'qs dev'. You are in %s branch ", rc.CurrentBranch) | ||
| } | ||
|
|
||
| // Stash current changes if needed | ||
| stashedUncommittedChanges := false | ||
| if ok, err := gitcmds.HaveUncommittedChanges(wd); ok { | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if rc.HasUncommittedChanges { | ||
| if err := gitcmds.Stash(wd); err != nil { | ||
| return fmt.Errorf("error stashing changes: %w", err) | ||
| } | ||
| stashedUncommittedChanges = true | ||
| } | ||
|
|
||
| // sync local MainBranch to ensure it's up to date with origin and upstream remotes | ||
| if err := gitcmds.SyncMainBranch(wd, mainBranch, upstreamExists); err != nil { | ||
| if err := gitcmds.SyncMainBranch(wd, rc.MainBranch, rc.UpstreamExists); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -124,25 +102,25 @@ func Dev(cmd *cobra.Command, wd string, doDelete bool, ignoreHook bool, args []s | |
|
|
||
| switch response { | ||
| case pushYes: | ||
| if len(parentRepo) > 0 && !upstreamExists { | ||
| if len(rc.ParentRepo) > 0 && !rc.UpstreamExists { | ||
| var upstreamResponse string | ||
| fmt.Print("Upstream not found.\nRepository " + parentRepo + " will be added as upstream. Agree[y/n]?") | ||
| fmt.Print("Upstream not found.\nRepository " + rc.ParentRepo + " will be added as upstream. Agree[y/n]?") | ||
| _, _ = fmt.Scanln(&upstreamResponse) | ||
| if upstreamResponse != pushYes { | ||
| fmt.Print(msgOkSeeYou) | ||
| return nil | ||
| } | ||
| if err := gitcmds.MakeUpstreamForBranch(wd, parentRepo); err != nil { | ||
| if err := gitcmds.MakeUpstreamForBranch(wd, rc.ParentRepo); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if err := gitcmds.CreateDevBranch(wd, devBranchName, mainBranch, notes); err != nil { | ||
| if err := gitcmds.CreateDevBranch(wd, devBranchName, rc.MainBranch, notes); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if issueInfo.Type == issue.GitHub { | ||
| notes, err = gitcmds.LinkBranchToGithubIssue(wd, parentRepo, issueInfo.Text, issueInfo.ID, devBranchName, args...) | ||
| notes, err = gitcmds.LinkBranchToGithubIssue(wd, rc.ParentRepo, issueInfo.Text, issueInfo.ID, devBranchName, args...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
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.
Minor: first-error-wins loses information.
When the first received
r.erris non-nil, the function returns immediately. The other four goroutines keep running, write to the buffered channel, and their results — including any further errors — are discarded silently. For a five-way fan-out this is probably fine in practice (and the channel is buffered tonumConcurrentso there is no goroutine leak), but consider either:errors.Join, so a real failure surfaces alongside any secondary failures, orfmt.Errorf("HasRemote(upstream): %w", err)inside each goroutine) so the caller can tell which sub-call actually failed.As written, a user only ever sees one bare error message with no indication of which of the five git calls produced it.