Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 1.66 KB

File metadata and controls

70 lines (49 loc) · 1.66 KB

scratch-git

Core diff engine for Scratch SB3 projects. Extracted and refactored from the original scratch-git project.

Stack

  • Rust library + CLI (lib + bin in one crate).
  • SB3 as ZIP: zip crate.
  • Text diff: similar (pure Rust, replaces git diff).

Build

cargo build --features=cli    # includes CLI binary
cargo build                   # library only

Test

cargo test --features=cli

CLI usage

# Compare two .sb3 files
scratch-git compare --old old.sb3 --new new.sb3 --format json

# Extract project.json from .sb3
scratch-git extract path.sb3

# Diff two raw text blocks
scratch-git diff-text "old content" "new content"

Library usage

use scratch_git::{compare_sb3, Diff};

// Compare two SB3 files
let commits = compare_sb3("old.sb3", "new.sb3").unwrap();

// Or compare two project.json values
let old = serde_json::from_str(old_json).unwrap();
let new = serde_json::from_str(new_json).unwrap();
let diff = Diff::new(&old);
let commits = diff.commits(&new).unwrap();

Key files

  • src/diff.rs — Core diff logic (assets, scripts, commits).
  • src/parse_script.rs — Scratch block JSON to text.
  • src/text_diff.rs — Pure Rust text diff (replaces git::diff).
  • src/zip.rs — SB3 (ZIP) reading.
  • src/sb3.rs — Asset extraction helpers.
  • src/utils.rs — Grouping/intersection utilities.

Go integration notes

The simplest way for blockcommit-gitea (Go) to consume this library is via CLI:

import "os/exec"

out, err := exec.Command("scratch-git", "compare", "--old", oldPath, "--new", newPath, "--format", "json").Output()
// parse JSON