Skip to content
Open
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
6 changes: 3 additions & 3 deletions cmd/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func runAdopt(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Parent is the required positional argument
parent := args[0]

Expand Down
10 changes: 5 additions & 5 deletions cmd/adopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func TestAdoptBranch(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand All @@ -40,8 +40,8 @@ func TestAdoptBranch(t *testing.T) {
func TestAdoptRejectsAlreadyTracked(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand All @@ -60,8 +60,8 @@ func TestAdoptRejectsAlreadyTracked(t *testing.T) {
func TestAdoptRejectsUntrackedParent(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand All @@ -81,8 +81,8 @@ func TestAdoptRejectsUntrackedParent(t *testing.T) {
func TestAdoptDetectsCycle(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -117,8 +117,8 @@ func TestAdoptDetectsCycle(t *testing.T) {
func TestAdoptStoresForkPoint(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func runCascade(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Check if cascade already in progress
if state.Exists(g.GetGitDir()) {
return errors.New("operation already in progress; use 'gh stack continue' or 'gh stack abort'")
Expand Down
2 changes: 1 addition & 1 deletion cmd/continue.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func runContinue(cmd *cobra.Command, args []string) error {

fmt.Printf("%s Completed %s\n", s.SuccessIcon(), s.Branch(st.Current))

cfg, err := config.Load(cwd)
cfg, err := config.New(g)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func runCreate(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Get current branch
currentBranch, err := g.CurrentBranch()
if err != nil {
Expand Down
15 changes: 7 additions & 8 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (
func TestCreateFromTrunk(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
cfg.SetTrunk("main")

g := git.New(dir)
cfg, _ := config.New(g)
cfg.SetTrunk("main")

// Simulate what create command does
currentBranch, _ := g.CurrentBranch()
Expand Down Expand Up @@ -57,8 +56,8 @@ func TestCreateFromTrunk(t *testing.T) {
func TestCreateFromTrackedBranch(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

currentBranch, _ := g.CurrentBranch()
cfg.SetTrunk(currentBranch)
Expand Down Expand Up @@ -86,8 +85,8 @@ func TestCreateFromTrackedBranch(t *testing.T) {
func TestCreateRejectsUntrackedBranch(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -119,8 +118,8 @@ func TestCreateRejectsUntrackedBranch(t *testing.T) {
func TestCreateWithStagedChanges(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -151,8 +150,8 @@ func TestCreateWithStagedChanges(t *testing.T) {
func TestCreateEmptyWithStagedChanges(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -197,8 +196,8 @@ func TestBranchAlreadyExists(t *testing.T) {
func TestCreateStoresForkPoint(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func runInit(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Determine trunk branch
trunk := trunkFlag
if trunk == "" {
Expand Down
6 changes: 4 additions & 2 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/boneskull/gh-stack/internal/config"
"github.com/boneskull/gh-stack/internal/git"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pulling in the Git wrapper defined in this commit.

)

func setupTestRepo(t *testing.T) string {
Expand Down Expand Up @@ -37,9 +38,10 @@ func TestInitCommand(t *testing.T) {
dir := setupTestRepo(t)

// Verify the config package works for init
cfg, err := config.Load(dir)
g := git.New(dir)
cfg, err := config.New(g)
if err != nil {
t.Fatalf("Load failed: %v", err)
t.Fatalf("New failed: %v", err)
}

err = cfg.SetTrunk("main")
Expand Down
6 changes: 3 additions & 3 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func runLink(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)
branch, err := g.CurrentBranch()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
func TestLinkPR(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -40,8 +40,8 @@ func TestLinkPR(t *testing.T) {
func TestLinkRejectsUntrackedBranch(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand All @@ -59,8 +59,8 @@ func TestLinkRejectsUntrackedBranch(t *testing.T) {
func TestLinkOverwritesPR(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down
6 changes: 3 additions & 3 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func runLog(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}
Expand All @@ -49,8 +51,6 @@ func runLog(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

g := git.New(cwd)
currentBranch, _ := g.CurrentBranch() //nolint:errcheck // empty string is fine for display

// Try to get GitHub client for PR URLs (optional - may fail if not in a GitHub repo)
Expand Down
10 changes: 7 additions & 3 deletions cmd/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"testing"

"github.com/boneskull/gh-stack/internal/config"
"github.com/boneskull/gh-stack/internal/git"
"github.com/boneskull/gh-stack/internal/tree"
)

func TestLogBuildTree(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)
cfg.SetTrunk("main")
cfg.SetParent("feature-a", "main")
cfg.SetParent("feature-b", "feature-a")
Expand Down Expand Up @@ -50,7 +52,8 @@ func TestLogBuildTree(t *testing.T) {
func TestLogEmptyStack(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)
cfg.SetTrunk("main")

// No branches tracked, just trunk
Expand All @@ -70,7 +73,8 @@ func TestLogEmptyStack(t *testing.T) {
func TestLogMultipleBranches(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)
cfg.SetTrunk("main")
// Two branches off main
cfg.SetParent("feature-a", "main")
Expand Down
6 changes: 3 additions & 3 deletions cmd/orphan.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func runOrphan(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Determine branch to orphan
var branchName string
if len(args) > 0 {
Expand Down
10 changes: 5 additions & 5 deletions cmd/orphan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func TestOrphanBranch(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -41,8 +41,8 @@ func TestOrphanBranch(t *testing.T) {
func TestOrphanRejectsWithChildren(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand All @@ -66,8 +66,8 @@ func TestOrphanRejectsWithChildren(t *testing.T) {
func TestOrphanForceWithDescendants(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -114,8 +114,8 @@ func TestOrphanForceWithDescendants(t *testing.T) {
func TestOrphanRemovesPR(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down Expand Up @@ -145,8 +145,8 @@ func TestOrphanRemovesPR(t *testing.T) {
func TestOrphanRemovesForkPoint(t *testing.T) {
dir := setupTestRepo(t)

cfg, _ := config.Load(dir)
g := git.New(dir)
cfg, _ := config.New(g)

trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
Expand Down
6 changes: 3 additions & 3 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func runSubmit(cmd *cobra.Command, args []string) error {
return err
}

cfg, err := config.Load(cwd)
g := git.New(cwd)

cfg, err := config.New(g)
if err != nil {
return err
}

g := git.New(cwd)

// Check if operation already in progress
if state.Exists(g.GetGitDir()) {
return errors.New("operation already in progress; use 'gh stack continue' or 'gh stack abort'")
Expand Down
Loading
Loading