#git #progress #remote #git-ops

bin+lib gitwrap

GitWrap is a simple wrapper around git command

14 releases (8 breaking)

0.11.0 Dec 28, 2024
0.9.1 Dec 23, 2024

#269 in Development tools

Download history 333/week @ 2024-12-01 444/week @ 2024-12-08 354/week @ 2024-12-15 480/week @ 2024-12-22 99/week @ 2024-12-29 2/week @ 2025-01-05

1,127 downloads per month

Apache-2.0

250KB
3.5K SLoC

GitWrap

Rust Report CardBuild Status License

GitWrap is a simple wrapper around git command.

The purpose of this library is to provide a controlled and reliable method of accessing the git commands in the simplest possible way.

This project is in progress, not all git commands / options are implemented yet.

Credits

This project is inspired and based on Go Git Cmd Wrapper

License

The code is licensed under the permissive Apache v2.0 licence. This means you can do what you like with the software, as long as you include the required notices. Read this for a summary.

Install

cargo install gitwrap

Running the above command will globally install the gitwrap binary. Install as library

Run the following Cargo command in your project directory:

cargo add gitwrap

Or add the following line to your Cargo.toml:

gitwrap = "0.11.0"

Usage

Here are some examples of use (work in progress)

1. Cloning a remote repo

use gitwrap::clone;


fn initialize(repo_url: &str, repo_path: &str) {
    let cmd = clone::clone()
        .add_option(clone::repository(repo_url))
        .add_option(clone::directory(repo_path));

    assert!(cmd.run().is_ok());
}

Clone a repo using macros. Macros allow to specify all command options and execute it in a single step

fn initialize(repo_url: &str, repo_path: &str) {
    assert!(
        clone!(
            options:
                clone::repository("https://github.com/japiber/gitwrap.git"),
                clone::directory(path.as_str())
        ).is_ok()
    );
}

Fine-grained control over the options command

fn set_repo_config(commit_email: &str, repo_path: &str) {
    let mut cmd = config::config();
    if (!commit_email.is_empty()) {
        cmd = cmd.add_option(config::entry("user.email", commit_email));
    }

    assert!(cmd.current_dir(repo_path).run().is_ok());
}

Execute a series of git commands at once with a BatchCommand or using the batch! macro

fn clean_repo(path: &str) {
    let s_path = Some(path);
    assert!(
        batch!(
            path: 
                s_path,
            commands:
                reset::reset(),
                checkout::checkout().add_option(checkout::pathspec(".")),
                clean::clean().add_options(vec![
                    clean::force(), 
                    clean::recurse_directories(), 
                    clean::no_gitignore()
                ])
        ).is_ok()
    );
}

Dependencies

~3–5MB
~95K SLoC