id: 002 title: Handle remote branch conflicts in init command status: completed type: enhancement priority: high tags: [init, remote, git] assignee: created: 2025-09-27T10:00:00Z updated: 2025-09-27T18:00:00Z completed: 2025-09-27T16:00:00Z
Handle remote branch conflicts in init command
Problem Description
The current tissue init command has several issues with remote branch handling that can lead to conflicts and unexpected behavior in distributed Git environments:
- Hardcoded remote assumption: The command assumes “origin” remote exists and pushes to it without verification (cmd/init.go:216)
- No remote branch detection: Doesn’t check if the issues branch already exists on any remote
- Multiple remotes not handled: When multiple remotes exist with the same branch name, there’s no way to specify which one to use
- Silent push failures: Push failures are only logged as warnings, potentially leaving users unaware of sync issues
Edge Cases to Consider
Case 1: No remotes configured
- Current: Skips push (correct behavior)
- Expected: Continue as-is ✓
Case 2: Single remote (not named “origin”)
- Current: Push fails silently
- Expected: Should detect and use the single remote
Case 3: Multiple remotes, none with issues branch
- Current: Pushes to “origin” if it exists
- Expected:
- if –remote flag set
- should check if that remote exists, and then push to it
- if –remote flag not set
- Should not push to any remote
- print output saying that no pushing has occured
- print how to tissue init with a remote (–remote flag)
- print how the user can set and push the issues branch/worktree with normal git commands
- if –remote flag set
Case 4: Multiple remotes, one has issues branch
- Current: May create conflicting local branch
- Expected: Should detect and:
- Log that the dectected matching remote branch was found
- Checkout and track the existing remote branch
Case 5: Multiple remotes, multiple have issues branch
- Current: Creates local branch, pushes to “origin”
- Expected: Should require explicit remote selection (–remote flag)
Proposed Solution
- Add
--remoteflag to specify which remote to use - Add
--force-localflag to bypass remote checks - Implement remote branch detection to avoid conflicts
- Smart remote selection:
- Single remote: use it automatically
- Multiple remotes: require –remote flag or skip push
- Detect and track existing remote branches
- Better error handling for SSH and connectivity issues
Test Cases Summary
- No remotes: Creates local branch, sets up worktree ✅
- Single remote (not “origin”): Auto-detects and uses it ✅
- Multiple remotes, no issues branch: Requires –remote flag or skips push ✅
- Multiple remotes, one has issues: Tracks existing branch ✅
- Multiple remotes, multiple have issues: Requires –remote flag ✅
- Unreachable remote: Shows warning, continues locally ✅
- Invalid –remote flag: Fails with clear error ✅
- Local issues branch exists: Fails with appropriate message ✅
- Local branch exists, worktree missing: Reuses branch ✅ Fixed
- SSH connectivity issues: Uses –force-local flag ✅ Fixed
Implementation Updates
Code Cleanup (2025-09-27)
- Removed redundant and obvious comments throughout the code
- Added git command equivalents as comments for clarity (e.g.,
git rm -rf .,git add,git push) - Simplified the
contains()function to usestrings.Contains() - Fixed syntax error (missing closing brace in file removal loop)
- Improved error handling consistency
- Removed empty else blocks and unnecessary control flow
- Made logging more deliberate and git-like (minimal output)
- Success message now shows only: “Initialized tissue in issues/”
SSH Handling Simplification
- Removed complex SSH config parsing that was “way out of control”
- Let go-git handle SSH authentication natively
- Added
--force-localflag to bypass remote checks when needed - Fail silently on SSH errors rather than blocking initialization