-
Notifications
You must be signed in to change notification settings - Fork 327
Add 'b' key for branch-based session creation #202
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
Conversation
Add comprehensive branch workflow with three-step process: 1. Session name input (same as 'n' key) 2. Branch name input (e.g., feat/new-feature) 3. Source branch selection (with smart defaults) Key improvements: - Fix modal display issues by switching from textarea to textinput - Fix title setting timing to prevent "cannot change title" errors - Remove branch prefix for user-specified names (respect exact input) - Convert if-else chains to tagged switches for better linting - Fix all import issues and errcheck warnings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
…rvation This commit implements two major enhancements to the branch creation workflow: ## 1. Remote Branch Sync Detection and Confirmation ### Source Branch Sync Check - Check if source branch (the "from" branch) needs sync with remote origin - Prompt user: "Source branch 'main' is out of sync with remote. Sync before creating? (y/n)" - Prevents creating branches from outdated local source branches ### Target Branch Sync Check - Check if target branch name already exists on remote with different commits - Prompt user: "Target branch 'feature' has different commits. Sync before creating? (y/n)" - Ensures branch creation uses most up-to-date remote state ### Implementation Details - Added `CheckRemoteBranchStatic()` and `SyncWithRemoteBranchStatic()` static methods - Enhanced `stateSourceBranch` workflow with two-stage sync confirmation - Added new helper methods: `syncSourceThenCheckTarget()`, `checkTargetBranchAndProceed()` - Uses `stateSyncConfirm` state with contextual confirmation overlays ## 2. Session Name Preservation ### Problem Fixed - 'b' key workflow was overwriting user session names with branch names - User enters session name "my-auth-session" but gets "feat/auth-flow" instead ### Solution - Modified `finalizeBranchCreation()` to only set branch name as title when no title exists - Preserves user-entered session names from 'b' key workflow - Maintains backward compatibility for direct branch creation ## Key Files Changed ### Core Logic - `app/app.go`: Enhanced branch creation workflow with remote sync checks - `session/git/worktree_ops.go`: Added static remote branch checking methods - `session/instance.go`: Added wrapper functions for static git operations ### Tests Added - `app/branch_sync_test.go`: Comprehensive tests for sync functionality and session preservation - `session/git/util_test.go`: Tests for remote branch detection and sync operations ## User Experience Flow **Before**: ``` 1. Press 'b' → Enter session name → Enter branch → Session renamed to branch name 2. No remote sync checking → potential outdated branches ``` **After**: ``` 1. Press 'b' → Enter session name → Enter branch name 2. Check source branch sync → Optional sync source 3. Check target branch sync → Optional sync target 4. Create session with preserved name and up-to-date branches ``` This enhancement ensures branch creation workflows are more reliable and user-friendly by preventing common git sync issues and respecting user session naming choices. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🚀 Major Updates Since Last WeekHey team! I've made significant enhancements to the branch creation workflow based on testing and user feedback. Here's what's new in the latest commit: 🔄 Remote Branch Sync Detection & ManagementProblem Solved: Users were creating branches from outdated local source branches that had diverged from remote origin, leading to merge conflicts and lost commits. Solution: Added intelligent 2-stage sync detection: 1. Source Branch Sync Check
2. Target Branch Sync Check
💾 Session Name PreservationProblem Solved: The 'b' key workflow was overwriting user session names with branch names. Before: User enters session name "my-auth-work" → gets session named "feat/auth-flow" ❌ This maintains clear separation between session organization and git branch naming. 🛠️ Technical ImplementationNew Static Methods ( func CheckRemoteBranchStatic(repoPath, branchName string) (exists bool, needsSync bool, err error)
func SyncWithRemoteBranchStatic(repoPath, branchName string) errorEnhanced State Machine (
Session Title Logic: // Only overwrite title if none provided (preserves 'b' key user input)
if selected.Title == "" {
selected.SetTitle(m.pendingBranchName)
}🧪 Comprehensive TestingNew Test Suite (
All tests pass - zero regressions, full backward compatibility maintained. 📈 Impact on User ExperienceBefore: After: 🔧 Why These Changes Matter
This brings the branch creation workflow up to production-ready standards for team development! Ready for review - all functionality tested and working seamlessly with existing workflows. |
This commit fixes an issue where using the same branch name for both source
and target in branch creation workflow would cause problems.
## Problem
When a user enters the same branch name for both "from branch" and "new branch":
- System tried to create a "new" branch with existing name
- Showed confusing sync confirmation for non-existent new branch
- Could fail or create unexpected behavior
- Session would be empty/broken after sync confirmation
## Solution
Added intelligent detection for same-branch scenario:
### Edge Case Detection
```go
if sourceBranch == m.pendingBranchName {
// This is existing branch checkout, not new branch creation
return m.handleSameBranchCheckout(selected, sourceBranch)
}
```
### New Workflow for Same Branch Names
1. **`handleSameBranchCheckout()`** - Detects this is existing branch operation
2. **Single sync check** - Only check if the existing branch needs sync
3. **`finalizeExistingBranchCheckout()`** - Sets up session with existing branch
4. **Clear messaging** - "Branch 'main' is out of sync. Sync before checkout? (y/n)"
### Key Differences from New Branch Creation
- **No new branch creation** - Uses existing branch directly
- **Single sync check** - Only one confirmation instead of two
- **Checkout vs Create** - Language reflects the actual operation
- **Source = Target** - Both CustomBranch and SourceBranch set to same value
## Implementation Details
### Methods Added
- `handleSameBranchCheckout()` - Entry point for same-branch scenario
- `finalizeSameBranchCheckout()` - Handles sync then checkout
- `finalizeExistingBranchCheckout()` - Final session setup for existing branch
### User Experience
**Before (broken)**:
```
Enter branch: "main" → Enter source: "main"
→ "Target branch 'main' has different commits. Sync? (y/n)"
→ Empty/broken session
```
**After (fixed)**:
```
Enter branch: "main" → Enter source: "main"
→ "Branch 'main' is out of sync with remote. Sync before checkout? (y/n)"
→ Working session with branch "main"
```
### Tests Added
- `TestSameBranchEdgeCase` - Comprehensive testing of same-branch scenario
- Verifies no panics, correct branch setup, and session title preservation
- Ensures both CustomBranch and SourceBranch are set to same value
This fix ensures the branch creation workflow handles all valid user inputs
gracefully, including the edge case of checking out existing branches.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
…origins **Problem:** - After creating branches via 'b' workflow from remote origins, branches lacked proper upstream tracking - `git pull` would fail with "There is no tracking information for the current branch" - Users had to manually run `git branch --set-upstream-to=origin/<branch>` **Root Cause:** - `setupFromExistingBranch()` created worktrees from remote branches but didn't set upstream tracking - Both paths (remote-only and local+remote scenarios) missed explicit upstream configuration **Solution:** - Added explicit `git branch --set-upstream-to=origin/<branch>` calls in both scenarios: 1. When local branch doesn't exist but remote does (line 84-87) 2. When both local and remote exist (line 95-100) - Added warning logging for tracking setup failures (non-fatal) - Preserves existing functionality while ensuring proper git pull/push behavior **Testing:** - All existing git tests pass (session/git package) - Fix handles both new and existing branch scenarios - Graceful degradation with warnings if upstream setup fails **Files Modified:** - session/git/worktree_ops.go: Added upstream tracking setup - .github/ISSUE_TEMPLATE/ux_enhancement.md: Created template for future UX issues This resolves the git pull tracking issue reported in auth-flow worktree scenario. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Applied gofmt formatting to session/git/worktree_ops.go to resolve make lint-basic errors. No functional changes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
**Enhanced User Experience:**
- Added comprehensive guidance messages when upstream tracking setup fails
- Provides exact command for users to run manually: `git branch --set-upstream-to=origin/<branch> <branch>`
- Created reusable helper function `showUpstreamTrackingMessage()` for consistent messaging
- Improved error messages in worktree setup with actionable instructions
**Key Improvements:**
1. **Helpful Error Messages**: Replace generic warnings with specific guidance
2. **User Empowerment**: Show exact commands to fix tracking issues manually
3. **Edge Case Support**: Especially beneficial for same-name branch scenarios
4. **Consistent UX**: Standardized messaging across different failure modes
**User Journey Enhancement:**
```
Before: "Warning: failed to set upstream tracking for branch feature: exit status 128"
After: "Warning: Unable to automatically set upstream tracking for branch 'feature'.
To enable git pull/push, run this command in your worktree:
git branch --set-upstream-to=origin/feature feature"
```
**Files Modified:**
- session/git/worktree_ops.go: Enhanced error messages with actionable guidance
- app/app.go: Added helper function for consistent upstream tracking messages
This addresses user feedback about needing manual upstream tracking setup,
especially after sync confirmations and in same-name branch edge cases.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Add 'b' Key for Branch-Based Session Creation with Remote Sync
Addresses #88 (provides manual workaround for flexible branch naming)
What
This PR adds comprehensive branch-based session creation functionality via the 'b' key, implementing a three-step workflow that allows users to create sessions with custom git branches, now enhanced with remote branch sync detection and session name preservation.
Key Features Added:
Why
Problem Statement:
Users needed a way to create sessions with specific git branch names for feature development, but the existing 'n' key only supported auto-generated branch names with configured prefixes.
Issues Addressed:
feat/user-authorhotfix/critical-bugHow
Implementation Details:
1. Core Branch Workflow (
app/app.go) - Enhanced2. 🆕 Remote Branch Sync System (
session/git/worktree_ops.go)3. 🆕 Session Name Preservation (
app/app.go)Before: Always overwrote session title with branch name
After: Preserves user session names
4. Instance Lifecycle Fix
Before: Instance started immediately after naming, preventing title updates
After: Instance starts only after complete configuration
5. UI Component Improvement (
ui/overlay/textInput.go)Before: Used
textarea.Model(multi-line) causing vertical text displayAfter: Switched to
textinput.Model(single-line) for proper display🆕 Enhanced User Experience Flow:
Before:
After:
Testing & Validation:
app/branch_sync_test.go)TestSessionTitlePreservation)TestSourceBranchSyncCheck)Workflow Comparison:
Examples
🆕 Enhanced 'b' Key Workflow:
b→ Enter session name:auth-feature-workfeat/user-authenticationdevelopauth-feature-workwith synced branchfeat/user-authenticationfrom updateddevelopAddresses Issue #88 - Flexible Branch Naming:
While this PR doesn't implement template-based automatic branch naming, it provides a manual solution that supports all the patterns requested in #88:
fix/issue-123-auth-bug- User can type exactly thisfeature/456/user-dashboard- User can type exactly this{user}/issue-789- User can manually enter their usernameThis gives users immediate access to flexible branch naming while a future PR could add template automation.
Backwards Compatibility:
🆕 Files Changed (Latest):
Core Enhancements:
app/app.go- Enhanced workflow with remote sync detection and session name preservationapp/branch_sync_test.go- NEW: Comprehensive tests for sync functionalitysession/git/worktree_ops.go- Added static remote branch checking methodssession/git/util_test.go- NEW: Tests for remote branch operationssession/instance.go- Added wrapper functions for static git operationsPrevious Changes:
keys/keys.go- Key binding for 'b'ui/overlay/textInput.go- UI component fixconfig/config_test.go- Error handling fixessession/tmux/tmux.go- Error handling fixesThis comprehensive implementation provides users with full control over branch-based development workflows with intelligent remote sync management while maintaining all existing functionality.