diff --git a/cmd/status.go b/cmd/status.go index 9eaf51c..2afe726 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -364,6 +364,32 @@ func detectSyncIssues(gitClient git.GitClient, stackBranches []stack.StackBranch } else if err != nil && verbose { fmt.Printf(" ⚠ Could not check if branch is behind: %v\n", err) } + + // Check if local branch differs from remote (needs push) + if gitClient.RemoteBranchExists(branch.Name) { + if verbose { + fmt.Printf(" Checking if local branch differs from origin/%s...\n", branch.Name) + } + localHash, localErr := gitClient.GetCommitHash(branch.Name) + remoteHash, remoteErr := gitClient.GetCommitHash("origin/" + branch.Name) + if localErr == nil && remoteErr == nil && localHash != remoteHash { + if verbose { + fmt.Printf(" ✗ Local branch differs from origin/%s (needs push)\n", branch.Name) + } + issues = append(issues, fmt.Sprintf(" - Branch '%s' differs from origin (needs push)", branch.Name)) + } else if localErr == nil && remoteErr == nil && verbose { + fmt.Printf(" ✓ Local branch matches origin/%s\n", branch.Name) + } else if verbose { + if localErr != nil { + fmt.Printf(" ⚠ Could not get local commit hash: %v\n", localErr) + } + if remoteErr != nil { + fmt.Printf(" ⚠ Could not get remote commit hash: %v\n", remoteErr) + } + } + } else if verbose { + fmt.Printf(" ℹ No remote branch origin/%s found\n", branch.Name) + } } return &syncIssuesResult{ diff --git a/cmd/status_test.go b/cmd/status_test.go index 8108949..b96cdca 100644 --- a/cmd/status_test.go +++ b/cmd/status_test.go @@ -211,6 +211,7 @@ func TestDetectSyncIssues(t *testing.T) { prCache: make(map[string]*github.PRInfo), setupMocks: func(mockGit *testutil.MockGitClient) { mockGit.On("IsCommitsBehind", "feature-a", "main").Return(true, nil) + mockGit.On("RemoteBranchExists", "feature-a").Return(false) }, expectedIssues: 1, expectedMerged: 0, @@ -240,6 +241,7 @@ func TestDetectSyncIssues(t *testing.T) { setupMocks: func(mockGit *testutil.MockGitClient) { mockGit.On("GetDefaultBranch").Return("main") mockGit.On("IsCommitsBehind", "feature-b", "feature-a").Return(false, nil) + mockGit.On("RemoteBranchExists", "feature-b").Return(false) }, expectedIssues: 1, // Issue because parent is merged expectedMerged: 0, diff --git a/cmd/sync.go b/cmd/sync.go index c005523..48c3d7e 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -129,10 +129,6 @@ func runSync(gitClient git.GitClient, githubClient github.GitHubClient) error { fmt.Printf("✓ Added '%s' to stack with parent '%s'\n", originalBranch, baseBranch) } - fmt.Println() - fmt.Println("Syncing stack...") - fmt.Println() - // Start parallel fetch operations (git fetch and GitHub PR fetch) // These are the slowest operations and have no dependencies between them var wg sync.WaitGroup