git-fast-import 0.1.0

A library for generating git fast-import streams
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 8 items with examples
  • Size
  • Source code size: 38.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.79 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • orf

A library for generating git fast-import streams.

This crate provides a simple, type-safe API for creating git commits programmatically by generating a stream that can be piped to git fast-import.

Example

Write to a buffer:

use git_fast_import::{GitFastImporter, GITHUB_BOT_AUTHOR};

let mut output = Vec::new();
let mut importer = GitFastImporter::new(
    &mut output,
    "main".to_string(),
    None,
    GITHUB_BOT_AUTHOR.to_string(),
);

let mut commit = importer.start_commit("Initial commit", chrono::Utc::now());
commit.add_file("hello.txt", b"Hello, World!").unwrap();
commit.finish().unwrap();
importer.finish().unwrap();

// `output` now contains a valid git fast-import stream

Pipe directly to git fast-import:

use git_fast_import::{GitFastImporter, GITHUB_BOT_AUTHOR};
use std::process::{Command, Stdio};

let mut child = Command::new("git")
    .args(["fast-import", "--quiet"])
    .stdin(Stdio::piped())
    .spawn()
    .expect("failed to spawn git fast-import");

let stdin = child.stdin.take().unwrap();
let mut importer = GitFastImporter::new(
    stdin,
    "main".to_string(),
    None,
    GITHUB_BOT_AUTHOR.to_string(),
);

let mut commit = importer.start_commit("Initial commit", chrono::Utc::now());
commit.add_file("src/lib.rs", b"// new file").unwrap();
commit.finish().unwrap();
importer.finish().unwrap();

let status = child.wait().expect("failed to wait on git fast-import");
assert!(status.success());