获取与 git push 相关的所有文件
get all files related to git push
有没有办法获取(可能使用服务器端挂钩)与推送相关的所有文件?喜欢:
当用户执行以下操作时:$
git push origin master
如果我们使用 $git 日志,那么挂钩必须具有 SHA-1 才能获取与推送相关的文件?
在服务器端,这通常在 a pre-receive or post-receive hook 中进行(取决于您是要允许推送还是只是 post 处理它)。
两个挂钩都获取从标准输入推送的引用列表。
例如见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=
newrev=
refname=
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 }'`
# If it's not present, then continue to the the next itteration
if [ -z ${object} ]; then
continue;
fi
...
在上面的示例中,它不仅推送了列表(提交后提交),还推送了它们的内容(git ls-tree ...|grep file
)
有没有办法获取(可能使用服务器端挂钩)与推送相关的所有文件?喜欢:
当用户执行以下操作时:$
git push origin master
如果我们使用 $git 日志,那么挂钩必须具有 SHA-1 才能获取与推送相关的文件?
在服务器端,这通常在 a pre-receive or post-receive hook 中进行(取决于您是要允许推送还是只是 post 处理它)。
两个挂钩都获取从标准输入推送的引用列表。
例如见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=
newrev=
refname=
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 }'`
# If it's not present, then continue to the the next itteration
if [ -z ${object} ]; then
continue;
fi
...
在上面的示例中,它不仅推送了列表(提交后提交),还推送了它们的内容(git ls-tree ...|grep file
)