id: 001 title: Implement init command status: completed type: feature created: 2025-09-24
Implement init command
Description
Implement the tissue init command to initialize issue tracking in a git repository. This command creates an orphan “issues” branch, sets up the proper directory structure, and optionally configures a git worktree for easy access.
Implementation Tasks
-
Update go.mod with go-git dependencies
- Add
github.com/go-git/go-git/v5 - Add
github.com/go-git/go-billy/v5
- Add
-
Implement repository validation
- Open repository with
git.PlainOpen(".") - Verify it’s a valid git repository
- Check if issues branch already exists
- Open repository with
-
Create orphan “issues” branch
- Store current branch reference to return later
- Create orphan branch using
plumbing.NewSymbolicReference - Set HEAD to point to new orphan branch
- FIXED: Clear index and working directory to ensure true orphan
-
Initialize branch structure
- Create README.md with issue tracker description
- Create .gitignore (ignore everything except markdown files)
- Stage files with
worktree.Add() - Commit as first commit on orphan branch
-
Handle remote operations
- Check for origin remote
- Push issues branch if remote exists
- Handle push failures gracefully
-
Return to original branch
- Checkout back to the branch stored at start
-
UPDATED: Implement automatic worktree setup with –issues-dir flag
- Always create worktree (no longer optional)
- Replace
--setup-worktreewith--issues-dir <dir>flag - Default to
./issuesif flag not provided - Use os/exec to run
git worktree add <dir> issues - Add
<dir>/to main branch .gitignore - Commit .gitignore update
-
ADDED: Support custom branch name with –issues-branch flag
- Added
--issues-branchflag for custom branch name - Default to
issuesbranch - Use constants
_issuesBranchDefaultand_issuesDirDefault - All branch references use the variable
- Added
-
Error handling
- Clear error messages for each failure case
- Handle bare repositories appropriately
- Validate operations at each step
- UPDATED: Refactored to follow Go error style guide
-
User feedback
- Progress messages for each operation
- Success confirmation
- Instructions for next steps
-
TODO: Use git-configured user for commits
- Read user.name and user.email from git config
- If not configured, prompt user (like git does)
- Don’t hardcode “Tissue CLI” as author
Technical Notes
- go-git v5 doesn’t support
git worktree addnatively - using os/exec as workaround - Track worktree support progress: https://github.com/go-git/go-git/pull/396
Acceptance Criteria
- Command creates orphan “issues” branch successfully
- Branch contains README.md and .gitignore
- UPDATED: Worktree is automatically created (no longer optional)
- UPDATED: –issues-dir flag allows custom directory name (defaults to ./issues)
- Proper error handling for edge cases
- Clear user feedback throughout process
- Returns to original branch after completion
Problems Encountered
Problem 1: Orphan branch not truly orphan
Fixed: The created “issues” branch was not truly orphan - it had parent commits and shared history with the main branch. Solution was to clear the index and working directory before committing.
Status
Completed:
- ✅ Creates a truly orphan branch (no parent commits)
- ✅ Initializes branch with README.md and .gitignore
- ✅ Automatically sets up git worktree
- ✅
--issues-dirflag allows custom directory (defaults to ./issues) - ✅
--issues-branchflag allows custom branch name (defaults to issues) - ✅ Pushes to remote if available
- ✅ Returns to original branch after completion
- ✅ Clear error messages and user feedback
Remaining:
- None - see issue #003 for git user config enhancement