A Ruby command line implementation for parsing and printing the Git index file.
See LICENSE.
The project consists of a Ruby module containing the file format definition based on BinData
DSL and a script for printing the parsed file content to the command line.
The module could be used standalone.
Prerequisite: Ruby installed.
-
Install required gems:
gem install bindata
-
Copy files under
src
to your local machine. Either to the root folder of a local Git repository or to any desired location. -
Ensure the script can be executed. On Linux/Unix ensure the shebang path is correct and give the script execution rights using
chmod
.
When at the root of a Git repository:
./show_index.rb
At an arbitrary location:
./show_index.rb --path=your/target/path/.git/index
To check options:
./show_index.rb --help
- Currently only tested with Git version 2.40.0 and version 2 of the index file format.
- Supported extensions: TreeCache, ResolveUndo. Data of other extensions is printed as raw string.
- Support for version 4 of the index file format not implemented.
- Only supports SHA1 based repositories.
- No plans to support sparse-checkout in cone mode.
The driver for this project was to better understand the internal workings of Git and the format in which the data is stored in the index file. It also seemed to be a good opportunity to get started with the Ruby programming language which I have not really used before. Was developed on/for Termux on a LG V30.
Similar projects:
- Python based Gin.
- C++ based git-print-index
Alternatively the Ruby rugged module (using libgit2
) could be used.
Much of the information could also be queried through Git plumbing commands.