6

I need to get a list of changed files in server-side hook. Example:

Local commit 1:

M test.txt
M test2.txt

Local commit 2:

M test.txt
A test3.txt

Both commits get pushed to the server (bare repo). I need to loop through the list of files AND post each of them through curl elsewhere:

M test.txt
M test2.txt
A test3.txt

I'm struggling to find the documentation to achieve this. I know the revisions are spit out to stdin. How do I actually loop through the pushed files, and reference them for a curl upload (this seems difficult since it's a bare repo)?

#!/bin/bash

while read oldrev newrev refname; do
  echo $oldrev
  echo $newrev
  echo $refname
done < "${1:-/dev/stdin}"
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Swiggity Swooty
  • 217
  • 3
  • 16
  • http://stackoverflow.com/questions/1552340/how-to-list-the-file-names-only-that-changed-between-two-commits – Andrew C Nov 02 '15 at 19:09
  • @AndrewC git diff won't work on a bare repository since there's no working directory. EDIT: I stand corrected, apparently it does work when specifying the references explicitly – Swiggity Swooty Nov 02 '15 at 19:10
  • It will when you provide it two SHAs. – Andrew C Nov 02 '15 at 19:12
  • @AndrewC Thanks for the link. This resolves looping through the pushed files. As for the second part, do you have any idea how to access the physical file / file bytes on the bare repository in order to post these through curl? I only need to do a read on the bytes. – Swiggity Swooty Nov 02 '15 at 19:28
  • `git show` or `git cat-file` ? – Andrew C Nov 02 '15 at 19:46

0 Answers0