Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git hooks for metadata storage/retrieval

Tags:

git

metadata

One of git's unavoidable quirks is its inability to store and retrieve metadata about a file. For example, on the mac, labels are stored with "extended attributes" (accessible with xattr), and any checkout/reset/merge/pull command will erase those attributes if the file is affected by the checkout.

I've looked around to see if someone has written metadata-saving scripts already, but I came up dry.

So what I'd like to do is use Git's hook system to:

  1. Read extended attributes when files are committed,
  2. Write the attributes to a file stored in the repository that also gets committed,
  3. Apply the extended attributes to files that are modified in a merge/checkout/reset.

Which of the hooks should I use? Are post-receive and pre-commit all that I need? Can pre-commit also add a file to the commit (i.e., after writing the new attributes)?

like image 747
Seth Johnson Avatar asked Feb 26 '10 14:02

Seth Johnson


People also ask

What are the Git hooks?

Git hooks are shell scripts found in the hidden . git/hooks directory of a Git repository. These scripts trigger actions in response to specific events, so they can help you automate your development lifecycle. Although you may never have noticed them, every Git repository includes 12 sample scripts.

Where are Git hooks stored?

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .

What is the best description for Git hooks?

Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle.


2 Answers

The gibak tool uses pre-commit and post-checkout to let its ometastore tool save/restore metadata (optionally including xattrs).

You do not want post-receive. It is run on the remote end of pushes. It runs for bare repositories, so it has no business trying to update any files from the contents of a pushed commit. Do it in post-checkout where you know you will have a working tree available.

like image 200
Chris Johnsen Avatar answered Oct 17 '22 01:10

Chris Johnsen


metastore is able to save and restore file metadata, storing it in a separate file (which you can include in your commits)

like image 45
loopbackbee Avatar answered Oct 17 '22 02:10

loopbackbee