Compare old and new file pushed to git repository with (preferably) python hook

I am sorry if this has been asked before, but I still can’t find a clear answer whether what I need to do is possible or not. Now what I need to do:

I need to let people clone file, which contains unique (key, value) pairs, modify this file (do anything to the values, but only add keys) and then push it back to git repo. Is there a way how I could check both files together (i.e. load the old file to memory to check keys weren’t modified the list with what was added? I thought git could be suitable for this as I won’t have to take care about implementing history of changes, diffs etc.

I already explored git hooks, but none of the server-side hooks I found seems to be able to do this (read whole file), as the pre-receive hook only receives changes and post-receive can’t block the push.

I have one idea: split the file in two, one only with keys (and pre-receive check there are no modified lines, only new ones) and another one with whole pairs, where any modifications can be done. However, I don’t know how to ensure integrity of the keys in both files.

Any hints or better ideas please?

  • Failed to compile python (Permission denied!) while deploying some changes in heroku
  • using Rietveld Code Review Tool for code review
  • PyCharm: multiple projects in same window, independent version control
  • How do I ignore PyCharm configuration files in a git repository?
  • Fetching a URL from a basic-auth protected Jenkins server with urllib2
  • how to pull, push with remote branch
  • Why does setuptools not understand git+https URLs?
  • Python Development in multiple repositories
  • One Solution collect form web for “Compare old and new file pushed to git repository with (preferably) python hook”

    You actually can check this in the pre-receive hook. The input to this hook is a list of lines of the form

    <old-sha1> <new-sha1> <ref name>

    and might look like this

    fa84d9ae4374c8675191e003565ad197e9584737 619afe11d5e85c192fb2bea066d214065c50b561 /refs/head/master

    For each of the refs you want to check, you can get the contents of both versions of the file by using

    git cat-file blob <sha1>:path/to/file

    This allows you to compute and compare the set of keys, and refuse the update by returning a non-zero error code if desired.

    Since the pre-receive hook can only refuse all ref updates or none of them, you could also implement this in the update hook, which gets called once per ref that is updated.

    Git Baby is a git and github fan, let's start git clone.