Rut is a clone of Git, written in Rust. I use it as a learning project to deepen my knowledge of both Git and Rust. I'm still rather new to Rust so I would not recommend anyone looking at this project as a good example for how to write Rust.
Currently I'm cheating a bit with this repository as I've not implemented support for remote repositories yet (i.e pushing and pulling). So here, I periodically push changes just so I have a backup of my project.
This work is based on James Coglan's fantastic book Building Git. It provides a detailed description of how Git works under the hood, as well as an implementation of a subset of Git in Ruby. I HIGHLY recommend it if you are interested in learning more about Git.
rut requires Rust and Cargo to be installed. It's been tested to work on
Rust/Cargo version 1.61. Your mileage may vary on other versions.
To try rut out, clone the repository and build the project:
$ git clone https://github.com/slarse/rut.git
$ cd rut
$ cargo buildThen you can run commands like so:
$ cargo run <command>For example, the commands I will run to commit this update of the README are the following:
$ cargo run add README.md
$ echo 'Add usage instructions to README' > .git/COMMIT_EDITMSG
$ cargo run commitRut currently supports the following subset of Git:
init- Initializes a repository in the current directory
add- It's possible to add a single path at a time
- If the path is a directory, every file the file tree rooted in that directory is added
rm- It's possible to remove a single file at a time
commit- Create a commit of the current index
- Author and email is taken from the
GIT_AUTHOR_NAMEandGIT_AUTHOR_EMAILenvironment variables or the global$HOME/.gitconfigfile. - The commit message is taken from the
.git/COMMIT_EDITMSGfile or the-moption.
status- Mostly up-to-par with
git status - Currently does not attempt to identify renamed files
- Accepts the
--porcelainflag to output in a format that is easier to parse
- Mostly up-to-par with
diff- Complete with context lines, chunk headers and color output!
- Accepts the
--cachedflag to compare the index to the last commit - Optionally takes two refs to compare them
restore- Restores a single file in the worktree
- Accepts the
--sourceoption that takes a reference (defaults to HEAD)
log- Shows the Git log starting from HEAD
- Accepts the
-n <number>option to limit the amount of logged commits - Accepts the
--onelineflag to produce abbreviated output
rev-parse- Parse a revision to an object id
branch- Create a new branch