#git #git-repository #tool #cli-tool #cli #git-hook

app git-metafile

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

2 releases

0.2.3 Jul 4, 2022
0.2.2 Jul 4, 2022

#1319 in Filesystem

Download history 19/week @ 2024-02-23 8/week @ 2024-03-01 55/week @ 2024-03-29 15/week @ 2024-04-05

70 downloads per month

MIT license

21KB
400 lines

Git Metafile

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.

#%GIT-METAFILE 1
# <path>  <mode>    <uid> <gid>
.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 git-metafile package from the Alpine’s community repository:

apk add git-metafile

On Arch Linux

If you’re using Arch Linux, you can install git-metafile package from AUR:

yay -S git-metafile

Or use another AUR helper.

Using cargo

If you’re a Rust developer, you can build and install git-metafile from crates.io using cargo:

cargo install git-metafile

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 git-metafile, you can use a pre-built binary.

On Linux, you can choose either a statically linked [1] (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): [x86_64] [aarch64] [armv7]
🐧 Linux (glibc)[x86_64] [ppc64le] [riscv64gc]
macOS: [x86_64]

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

  2. Download and extract release tarball for your OS and CPU architecture (pick the right link from the list above):

    curl -sSLO https://github.com/jirutka/git-metafile/releases/download/v0.2.3/git-metafile-0.2.3-x86_64-linux.tar.gz
    curl -sSL https://github.com/jirutka/git-metafile/releases/download/v0.2.3/checksums.txt | sha256sum -c --ignore-missing
    tar -xzf git-metafile-0.2.3-*.tar.gz
    
  3. Install git-metafile somewhere on your PATH, e.g. /usr/local/bin:

    install -m 755 git-metafile-0.2.3-*/git-metafile /usr/local/bin/
    

From source tarball

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

  2. Download and unpack the tarball:

    wget https://github.com/jirutka/git-metafile/archive/v0.2.3/git-metafile-0.2.3.tar.gz
    tar -xzf git-metafile-0.2.3.tar.gz
    cd git-metafile-0.2.3
    
  3. Build git-metafile using cargo:

    cargo build --release --locked
    
  4. Grab the binary from target/release/git-metafile and install it somewhere on your PATH, e.g. /usr/local/bin:

    install -D -m755 target/release/git-metafile -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:

cat >> .git/hooks/pre-commit <<EOF
#!/bin/sh

git-metafile save && git add .metafile
EOF

chmod +x .git/hooks/pre-commit

cat >> .git/hooks/post-checkout <<EOF
#!/bin/sh

git-metafile apply
EOF

chmod +x .git/hooks/post-checkout
ln -s post-checkout .git/hooks/post-rewrite

This should work for all basic operations, so you don’t need to think about it anymore. However, you have to be careful when rebasing – no hook is run when git checkouts files during rebase and before committing changes done in rebase mode!

To record changes or restore files attributes manually, you can run git metafile save or git metafile apply respectively.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.

  1. Statically linked with musl libc

Dependencies

~1.5MB
~38K SLoC