首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

shell 更新全部git目录

2012-10-07 
shell 更新所有git目录有时候,很久不接触的项目,突然要更新使用,而又懒的一个目录一个目录的去做更新处理,

shell 更新所有git目录

有时候,很久不接触的项目,突然要更新使用,而又懒的一个目录一个目录的去做更新处理,顾整理了一个shell脚本来做处理,同时也做为之前写的一篇文章的更新吧!链接?:http://genggeng.iteye.com/blog/1128679

?

代码如下:

?

#!/bin/bash -x PROJECTS_DIR=/home/gavingeng/projects/emailfunction update_all(){    for d in `ls`    do      #  echo $d;          cd $PROJECTS_DIR/$d        echo "update project:current_dir: $PWD"        `git pull` >>/home/gavingeng/tmp/test.log 2>&1 &         sleep 5        echo "update success  ^_^"    done}function update(){    echo "hello ,u can update"      `git pull` >>/tmp/test.log 2>&1 &    echo "update success  ^_^"}cd $PROJECTS_DIRif [ -z  "$1"  ];then    update_allelif [ -d  "$PROJECTS_DIR/$1" ];then    cd $PROJECTS_DIR/$1    echo $PWD    updateelse    echo "not exist "$PROJECTS_DIR/$1""    exit 0;fi

?

在做git更新时,若没有更新,就会出现"Already date to date",这里将它重定向到日志中做处理

?

今天又对脚本进行了更新、处理,如下:

?

#!/bin/bash -x PROJECTS_DIR=/home/gavingeng/projects/email##排除以下情况:##1.非目录##2.非git目录function is_git_dir(){    param=`find $PWD -name ".git"`    if [ -z "$param" ];thenreturn 1 #1为假    elsereturn 0 #0为真    fi    }function update_all(){    for d in `ls`    do    if [ -d "$PROJECTS_DIR/$d" ];then    #  echo $d;              cd $PROJECTS_DIR/$d    if is_git_dir $PWD;then      echo "update project:current_dir: $PWD"      `git pull` >>/home/gavingeng/tmp/test.log 2>&1 &        sleep 5      echo "update success  ^_^"    elseecho "$PWD is not a git dir!"    fielse    echo "$d is not a dirctory"fi    done}function update(){    echo "hello ,u can update"    `git pull` >>/tmp/test.log 2>&1 &    echo "update success  ^_^"}cd $PROJECTS_DIRif [ -z  "$1"  ];then    update_allelif [ -d  "$PROJECTS_DIR/$1" ];then    cd $PROJECTS_DIR/$1    echo $PWD    if is_git_dir $PWD;then    update    elseecho "$PWD is not a git dir!"    fielse    echo "not exist "$PROJECTS_DIR/$1""    exit 0;fi
?

改完后,发现if/else逻辑更多了,该想想如何去改了......

?

?

热点排行