git-metafile

Crates.iogit-metafile
lib.rsgit-metafile
version0.2.3
sourcesrc
created_at2022-07-04 15:30:17.644374
updated_at2022-07-04 18:44:52.627597
descriptionA simple tool for storing and restoring files metadata (mode, owner, group) in a git repository. It's designed especially for versioning /etc.
homepagehttps://github.com/jirutka/git-metafile
repositoryhttps://github.com/jirutka/git-metafile
max_upload_size
id619022
size23,915
Jakub Jirutka (jirutka)

documentation

README

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
Commit count: 66

cargo fmt