git查看两个分支间不同文件列表并打包

#!/bin/bash
set -- `getopt p:b:s:e:f:o: $*`
getopt_rc=$?
if [ "$getopt_rc" -ne "0" ]; then
  pgm=`basename $0`
  echo "$pgm $getopt_rc Process failed during getopt attempt - illegal parameters"
  exit 10
fi
  while [ $# -gt 0 ]; do
    case $1 in
      -p)
         shift
         PROJECT=$1
         shift
         ;;
      -b)
         shift
         BRANCH=$1
         shift
         ;;
      -s)
         shift
         SHA_FROM=$1
         shift
         ;;
      -e)
         shift
         SHA_END=$1
         shift
         ;;
      -f)
         shift
         FUNCTION=$1
         shift
         ;;
      -o)
         shift
         OPERATE=$1
         shift
         ;;
      --)
         shift
         break
    esac
    
  done
  
COMMIT_FROM=$(git rev-parse $SHA_FROM)
if [[ $? -ne 0 ]];then
        echo 'the start commit id not exist'
        exit
fi
  
COMMIT_TO=$(git rev-parse $SHA_END)
if [[ $? -ne 0 ]];then
        echo 'the end commit id not exist'
        exit
fi
  
TO_FILES=$(date +'%Y%m%d')"_"${FUNCTION}".files"
FABFILE_DIR='/var/www/gongsi/shell/release'
  
case "$PROJECT" in
    "xuejiehome")
             PROJECT_PATH='/var/www/www.xuejiehome.com'
         ;;
    "xuejieblog")
             PROJECT_PATH='/var/www/www.xuejieblog.com'
             ;;
esac
  
if [ -z "$BRANCH" ]; then
        echo  '[-b] : branch can not empty.'
        exit 0
fi
  
if [ -z "$COMMIT_FROM" ]; then
        echo  '[-s] : start commit id can not empty.'
        exit 0
fi
  
if [ -z "$COMMIT_TO" ]; then
        echo  '[-e] : end commit id can not empty.'
        exit 0
fi
  
if [ -z "$FUNCTION" ]; then
        echo  '[-f] : function can not empty.'
        exit 0
fi
  
  
if [ -z "$PROJECT_PATH" ]; then
    echo  '[-p] : this project not exist.'
    exit 0
fi
  
if [ -z "$OPERATE" ]; then
        echo  '[-o] : operate can not empty.'
        exit 0
fi
  
cd $PROJECT_PATH
  
git checkout $BRANCH
   
#git pull origin $BRANCH
  
if [[ $? -ne 0 ]];then
    echo 'this branch not exist'
        exit
fi
# 如操作为非上线则打包文件
if [ "$OPERATE"x != "to_product"x  -a "$OPERATE"x != "to_pack"x ]; then
    git diff $COMMIT_FROM $COMMIT_TO --name-status|awk '{if($1!="D") {print $2}}' > $FABFILE_DIR/$PROJECT/$TO_FILES
  
    cd $FABFILE_DIR && fab to_pack:$PROJECT,$TO_FILES 
  
fi
# 执行操作
cd $FABFILE_DIR && fab $OPERATE:$PROJECT,$TO_FILES

调用:

sudo ./update_code.sh -b develop -s start_commint_id -e end_commint_id -f code_description -p project_name -o operate

注意:

develop:分支名称

start_commint_id:从该commit id开始(git log可获取)

end_commint_id:到该commit id结束(git log -1 可获取

code_description: 该部分代码块的功能

project_name:项目名称 (case里面的xuejiehome/xuejieblog)

operate:操作 (to_test/to_product)

by 雪洁 2015-02-02 08:12:59 1971 views
我来说几句

相关文章