How to get list of changed files in Git post-receive hook?
Asked Answered
B

0

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}"
Beutler answered 2/11, 2015 at 19:6 Comment(5)
#1552840Proulx
@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 explicitlyBeutler
It will when you provide it two SHAs.Proulx
@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.Beutler
git show or git cat-file ?Proulx

© 2022 - 2024 — McMap. All rights reserved.