An open API service indexing awesome lists of open source software.

https://github.com/jirutka/git-metafile

Store and restore files metadata (mode, owner, group) in a git repository
https://github.com/jirutka/git-metafile

git linux metadata rust

Last synced: about 1 month ago
JSON representation

Store and restore files metadata (mode, owner, group) in a git repository

Awesome Lists containing this project

README

          

= Git Metafile
Jakub Jirutka
//custom
:name: git-metafile
:version: 0.2.3
:gh-name: jirutka/{name}
:gh-branch: master
:releases-uri: https://github.com/{gh-name}/releases/download/v{version}

ifdef::env-github[]
image:https://github.com/{gh-name}/workflows/CI/badge.svg[CI Status, link=https://github.com/{gh-name}/actions?query=workflow%3A%22CI%22]
image:https://img.shields.io/crates/v/{name}.svg[Version on crates.io, link=https://crates.io/crates/{name}]
image:https://repology.org/badge/tiny-repos/{name}.svg[Packaging status, link=https://repology.org/project/{name}]
endif::env-github[]

A simple tool for storing and restoring complete files metadata (mode, owner, group) in a git repository.
It’s designed especially for versioning /etc.

Metadata is tracked using the `.metafile` file, which is automatically updated and added to commits.
This file is in TSV (tab-separated values) format to be easily readable and diffable.

._Sample .metafile_
[source]
----
#%GIT-METAFILE 1
#
.gitignore 100644 0 0
.metafile 100644 0 0
profile.d 40755 0 0
shadow 100640 0 42
----

== Installation

=== On Alpine Linux

If you’re using *Alpine Linux*, you can install https://pkgs.alpinelinux.org/packages?name={name}[{name}] package from the Alpine’s community repository:

[source, sh, subs="+attributes"]
apk add {name}

=== On Arch Linux

If you’re using *Arch Linux*, you can install https://aur.archlinux.org/packages/{name}[{name}] package from https://aur.archlinux.org/[AUR]:

[source, sh, subs="+attributes"]
yay -S {name}

Or use another AUR helper.

=== Using cargo

If you’re a *Rust developer*, you can build and install https://crates.io/crates/{name}[{name}] from https://crates.io/[crates.io] using `cargo`:

[source, sh, subs="+attributes"]
cargo install {name}

Note that the binary may be bigger than expected because it contains debug symbols.
To remove debug symbols and therefore reduce the file size, run `strip` on the binary.

=== Using pre-built binary

If your package manager doesn’t provide {name}, you can use a pre-built binary.

On Linux, you can choose either a statically linked footnote:[Statically linked with http://www.musl-libc.org/[musl libc]] *(static)* binary that should work on every Linux system (distro), or, if you’re using a sufficient recent GNU/libc-based *(glibc)* distro (most major distros), a dynamically linked binary.

____
🐧 *Linux (static)*:
{releases-uri}/{name}-{version}-x86_64-linux.tar.gz[[x86_64\]]
{releases-uri}/{name}-{version}-aarch64-linux.tar.gz[[aarch64\]]
{releases-uri}/{name}-{version}-armv7-linux.tar.gz[[armv7\]] +
🐧 *Linux (glibc)*:{nbsp}
{releases-uri}/{name}-{version}-x86_64-linux-gnu.tar.gz[[x86_64\]]
{releases-uri}/{name}-{version}-powerpc64le-linux-gnu.tar.gz[[ppc64le\]]
{releases-uri}/{name}-{version}-riscv64gc-linux-gnu.tar.gz[[riscv64gc\]] +
 *macOS*:
{releases-uri}/{name}-{version}-x86_64-apple-darwin.tar.gz[[x86_64\]]
{releases-uri}/{name}-{version}-aarch64-apple-darwin.tar.gz[[aarch64\]]footnote:[aarch64-apple-darwin is so called “Apple Silicon”.]
____

. Install git (use your system’s package manager).

. Download and extract release tarball for your OS and CPU architecture (pick the right link from the list above):
+
[source, sh, subs="verbatim, attributes"]
----
curl -sSLO {releases-uri}/{name}-{version}-x86_64-linux.tar.gz
curl -sSL {releases-uri}/checksums.txt | sha256sum -c --ignore-missing
tar -xzf {name}-{version}-*.tar.gz
----

. Install `{name}` somewhere on your `PATH`, e.g. `/usr/local/bin`:
+
[source, sh, subs="verbatim, attributes"]
install -m 755 {name}-{version}-*/{name} /usr/local/bin/

=== From source tarball

. Install git (use your system’s package manager).

. Download and unpack the tarball:
+
[source, sh, subs="+attributes"]
----
wget https://github.com/{gh-name}/archive/v{version}/{name}-{version}.tar.gz
tar -xzf {name}-{version}.tar.gz
cd {name}-{version}
----

. Build {name} using cargo:
+
[source, sh]
cargo build --release --locked

. Grab the binary from `target/release/{name}` and install it somewhere on your `PATH`, e.g. `/usr/local/bin`:
+
[source, sh, subs="+attributes"]
install -D -m755 target/release/{name} -t /usr/local/bin/

== How to use

To automatically record files attributes on every commit and restore them on every checkout, set up git hooks:

[source, sh]
----
cat >> .git/hooks/pre-commit <> .git/hooks/post-checkout <