wlk 0.1.0

File-centric, event-sourced version control system with implicit branching
Documentation
// Basic WLK usage example
// Run with: cargo run --example basic_usage

use std::fs;
use tempfile::TempDir;
use wlk::{DeltaOperation, Repository, ShadowFile};

fn main() -> anyhow::Result<()> {
    println!("=== WLK Basic Usage Example ===\n");

    // Create temporary directory for demo
    let temp_dir = TempDir::new()?;
    let work_dir = temp_dir.path();

    // 1. Initialize repository
    println!("1. Initializing WLK repository...");
    let mut repo = Repository::init(work_dir)?;
    println!("   ✓ Repository initialized\n");

    // 2. Create and track a file
    println!("2. Creating and tracking a file...");
    let file_path = work_dir.join("example.txt");
    fs::write(&file_path, "Hello, WLK!")?;

    repo.track_file(&file_path)?;
    println!("   ✓ File tracked: example.txt\n");

    // 3. Make changes and create snapshot
    println!("3. Making changes...");
    fs::write(&file_path, "Hello, WLK!\nThis is a new line.")?;

    let shadow_path = ShadowFile::shadow_path(&file_path)?;
    let mut shadow = ShadowFile::load(&shadow_path)?;

    let content = fs::read_to_string(&file_path)?;
    shadow.apply_delta(
        DeltaOperation::Snapshot { content },
        Some("Added new line".to_string()),
    )?;
    shadow.save(&shadow_path)?;
    println!("   ✓ Snapshot created\n");

    // 4. Check status
    println!("4. Checking repository status...");
    let status = repo.get_status()?;
    println!("   Files tracked: {}", status.len());
    for item in &status {
        println!(
            "   - {:?} ({:?})",
            item.path.file_name().unwrap(),
            item.status
        );
    }
    println!();

    // 5. View history
    println!("5. Viewing file history...");
    let shadow = ShadowFile::load(&shadow_path)?;
    let history = shadow.get_history();
    println!("   Total deltas: {}", history.len());
    for delta in history {
        if let Some(annotation) = &delta.annotation {
            println!("   - {} ({})", delta.id, annotation);
        }
    }
    println!();

    // 6. Time travel - rewind to previous version
    println!("6. Rewinding to previous version...");
    let initial_id = shadow.initial_snapshot.id.clone();
    let initial_content = shadow.reconstruct_at(&initial_id)?;
    println!("   Original content: {:?}", initial_content);

    let current_content = shadow.current_content()?;
    println!("   Current content: {:?}\n", current_content);

    // 7. List tracked files
    println!("7. Listing all tracked files...");
    let tracked = repo.list_tracked_files()?;
    println!("   Tracked files: {}", tracked.len());
    for file in tracked {
        println!("   - {:?}", file.file_name().unwrap());
    }

    println!("\n=== Example Complete! ===");
    println!("WLK provides file-centric version control with implicit branching.");
    println!("Each file has its own complete history and can branch independently.");

    Ok(())
}