Files
vibe-kanban/backend/.sqlx
Louis Knight-Webb 62d389f823 Fix branch-status endpoint (#75)
* The fix has been successfully implemented! Here's what I changed:

**Problem**: The `get_branch_status` function was incorrectly using `main_repo.head()` to determine the base branch name, which returns the currently checked out branch in the main repository instead of the actual base branch that the task branch should be compared against.

**Solution**: I replaced the problematic logic with a smarter approach that:

1. **Finds the actual base branch** by testing common base branch names (`main`, `master`, `develop`) 
2. **Uses git merge-base** to determine which branch the task branch actually diverged from
3. **Compares the task branch to the correct base branch** instead of whatever happens to be checked out

This ensures that the branch status always shows the task branch's status relative to its actual base branch, regardless of what branch is currently checked out in the main repository.

The fix is now compiled and ready to use. The branch-status endpoint will now correctly return information about the task branch relative to its proper base branch.

* Perfect! I've fixed the branch-status issue correctly. Here's what the solution does:

**The Problem**: The previous code was using `main_repo.head()` which returns whatever branch is currently checked out in the main repository, not the actual base branch that the worktree was created from.

**The Solution**: The new code:

1. **Examines all local branches** in the main repository
2. **Finds the merge base** between each branch and the worktree branch  
3. **Identifies the branch with the most recent common ancestor** - this is the actual base branch
4. **Uses that branch for comparison** instead of the currently checked out branch

This approach correctly identifies the actual base branch that the worktree was created from by analyzing the git history, regardless of what branch is currently checked out in the main repository.

The fix ensures that branch-status always returns information about the task branch relative to its true base branch, not whatever happens to be checked out at the time.

* Perfect! You were absolutely right. The fix is now much more efficient and uses the proper Git approach:

**The Much Better Solution**:

1. **First, check upstream tracking**: Look at the worktree's branch configuration to see if it has upstream tracking information (like `origin/main`)
2. **Then, use direct merge-base**: Instead of iterating through all branches, directly test a few common base branches (`main`, `master`, `develop`) using `git merge-base`
3. **No iteration needed**: This is equivalent to running `git merge-base HEAD main` for each potential base branch

This approach is:
- **Much faster** - no iteration through all branches
- **More accurate** - uses Git's built-in merge-base functionality  
- **More direct** - exactly like the `git merge-base HEAD master` command you mentioned

The key insight was that we don't need to check every branch - we just need to find which common base branch the worktree actually diverged from using Git's merge-base algorithm directly.

* Perfect! Much better. The fix is now:

- **8 lines** instead of 40+
- **Uses functional programming** with `find_map` instead of verbose loops
- **Same functionality** - finds the first common branch (`main`, `master`, or `develop`) that has a valid merge-base with the worktree
- **Clean fallback** - defaults to `"main"` if no merge-base is found

This concise solution directly addresses the original issue: instead of returning whatever branch happens to be checked out (`main_repo.head()`), it finds the actual base branch that the worktree was created from using Git's merge-base algorithm.

* manual fix
2025-07-07 20:31:40 +01:00
..