Skip to content

Feature: Branch Operations (checkout, merge, rebase) #6

@BishopMowle

Description

@BishopMowle

Overview

Implement advanced branch operations to enable switching branches, merging, and rebasing, matching isomorphic-git feature parity.

Commands to Implement

  • checkout - Switch branches or restore working tree files
  • switch - Switch branches (modern alternative to checkout)
  • merge - Merge one branch into another
  • abortMerge - Abort an in-progress merge
  • rebase - Reapply commits on top of another base tip
  • listBranches - List all local (and optionally remote) branches
  • deleteBranch - Delete a branch
  • currentBranch - Get the current branch name

Acceptance Criteria (AC)

  1. AC1: Checkout Functionality - Can switch between branches, preserving working tree changes
  2. AC2: Merge Functionality - Can perform fast-forward and recursive merges with conflict detection
  3. AC3: Rebase Functionality - Can rebase a branch onto another with proper commit replay
  4. AC4: Branch Listing - Can list all branches and identify current branch
  5. AC5: Merge Conflict Handling - Properly detects and reports merge conflicts without auto-resolving
  6. AC6: Abort Operations - Can abort in-progress merge/rebase operations

Definition of Done (DoD)

  • All commands implemented with proper error handling
  • Unit tests with >80% coverage
  • Interop tests passing
  • Documentation in README.md
  • No TypeScript errors or warnings

Interop Test Method

// Setup test repo
const repoDir = '/tmp/test-branch-ops';
await tsGit.init({ fs, dir: repoDir, defaultBranch: 'main' });
// Create commits on main and feature branches...

// Test merge
await tsGit.merge({ fs, dir: repoDir, ours: 'main', theirs: 'feature' });
const tsGitLog = await tsGit.log({ fs, dir: repoDir, depth: 3 });

// Compare with canonical git
execSync('git merge feature', { cwd: '/tmp/ref-repo' });
const refLog = execSync('git log --oneline -3', { cwd: '/tmp/ref-repo' }).toString();

// Verify merge commit structure matches

Validation Strategy:

  1. Create identical repo state in ts-git and canonical git
  2. Perform branch operations (checkout, merge, rebase)
  3. Compare resulting commit graph, tree state, and branch refs
  4. Test conflict scenarios with prepared conflict files

Priority

High - Essential for collaborative workflows

Dependencies

  • Requires plumbing commands (cat-file, update-index) for tree manipulation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions