使用git hook逐行获取输出

时间:2016-04-19 13:16:58

标签: git bash output hook

我在服务器上有一个post-receive挂钩:

#!/bin/sh

cd /var/www/project/sources || exit 1
unset GIT_DIR
git pull hub master

我在/ project / source上有一个post-merge挂钩:

#!/bin/sh

sh /var/git/hooks-scripts/clean /var/www/project/sources

当我运行git push时,一切正常,除了我的/var/git/hooks-scripts/clean脚本的输出在完成所有内容时发送,而不是逐行发送。如何逐行输出?

编辑:

根据要求,干净的脚本

#!/bin/bash

# define composer cache firectory
export COMPOSER_CACHE_DIR="/tmp/.composer-cache"

no_color="\\033[0;39m"
blue="\\033[1;34m"
yellow="\\033[1;33m"
green="\\033[0;32m"

end_script() {
    echo "\n${yellow}*** Configuration du projet ${blue}BAO${yellow} terminé ***${no_color}\n"

    exit $1
}

check_run() {
        echo "$changed_files" | grep --quiet "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2"
}

echo "\n${yellow}*** Configuration du projet ${blue}BAO${yellow} en cours ***${no_color}\n"

cd $1/scripts/cli || end_script 0

php console.php clean cache
php console.php clean thumbnails
php console.php symlink modules

cd $1

changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
check_run composer.lock "composer update -q -o"

echo "${green}✔${no_color} done"

end_script 0

0 个答案:

没有答案