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.

  • Why use rebase if it forces you to stay local?
  • Gradle script to autoversion and include the commit hash in Android
  • composer dump autoload and git
  • File Level Tracking In Git (Files from multiple branches in same directory)
  • Git command output shows special characters
  • Setting up PHPUnit with Gitlab Continuous Integration
  • 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?

  • How do I find all git revisions of a file which contains foo?
  • Unable to push a git repo via HTTP
  • Can someone explain 'git revert …'
  • git-subtree without squash: view log
  • How do I push files specified in .gitignore?
  • Can you record the git revision with gruntjs
  • 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.