Reputation: 9785
is there a way to get ( perhaps with a server side hook ) all the files related to a push ? like :
when a user does : $
git push origin master
if we use $git log then, somehow the hook has to have the SHA-1 in order to get the files related to the push ?
Upvotes: 2
Views: 107
Reputation: 1329082
On the server side, this is generally do in a pre-receive or post-receive hook (depending if you want to allow the push or just post-process it).
Both hooks take a list of references that are being pushed from stdin.
See for instance this gist:
#!/bin/bash
echo "### Attempting to validate puppet files... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
oldrev=$1
newrev=$2
refname=$3
while read oldrev newrev refname; do
# Get the file names, without directory, of the files that have been modified
# between the new revision and the old revision
files=`git diff --name-only ${oldrev} ${newrev}`
# Get a list of all objects in the new revision
objects=`git ls-tree --full-name -r ${newrev}`
# Iterate over each of these files
for file in ${files}; do
# Search for the file name in the list of all objects
object=`echo -e "${objects}" | egrep "(\s)${file}\$" | awk '{ print $3 }'`
# If it's not present, then continue to the the next itteration
if [ -z ${object} ]; then
continue;
fi
...
In the example above, it not only get the list (commit after commit) pushed, but also their content (with git ls-tree ...|grep file
)
Upvotes: 2