码疯窝

当项目用git跟composer管理的时候, 修改了composer就不用每次都去通知别人install一下了.
利用git的post-merge hook 去实现. 每次 git pull的时候就可以自动判断是否修改过composer 然后会提示你install.

#!/bin/bash
# Put this file at: .git/hooks/post-merge
# and make it executable

NOCOLOR='\033[0m'
REDCOLOR='\033[37;41m'
if [[ -f composer.lock ]]; then
    DIFF=`git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | grep composer.lock`
    if [[ $DIFF != "" ]]; then
        echo -e "$REDCOLOR composer.lock has changed. You must run composer install$NOCOLOR"
        echo -n "Run composer install? (yes or no)?"
        read Arg
		case $Arg in
		Y|y|YES|yes)
			composer install;;
		N|n|NO|no)
		  	exit;;
		"")
		esac
    fi
fi

效果图:
tmp

继续查看有关 技术随笔的文章

3个访客评论

  1. 路过

    不错哦,很实用

    qweqwe Reply
  2. |▍婷°!

    能不能让他不提示直接 install 啊…提示神马的最不喜欢了.

    qweqwe Reply
    • Gcaufy

      亲, 就那么几行代码我都贴上来了

      qweqwe Reply