shell创建git项目
公司一直在使用git来做项目管理,对于git与svn的优劣对比,大家可去google经常要去创建一些git项目来做新项目的开发,一些流程化的操作,每次去做就比较烦感,顾就想写个脚本来做去这些工作!业余时间整理了下,测试后,已满足现在的要求!后续有时间将做一些优化,包括:
1. web化来做对文件系统进行操作处理,对于项目成员、成员累计数,项目数等都存入DB中,做界面的操作!这样就不再需要客户端的git安装要求及操作系统要求。
2. 创建项目时,申请者提交申请给管理员,由管理员做审批校验后,授权该成员管理此项目,其实就是个马甲!
3. 项目排重(此脚本未做项目排重处理)
4. 。。。。。。
脚本如下,可做参考:
#!/bin/bash
#创建一个git项目的脚本
PROJECTS_DIR="/home/gavingeng/projects/email/"
GIT_PROJECT_DIR=$PROJECT_DIR"gitosis-admin/"
#GIT_PROJECT_DIR="/home/gavin/test"
#use info
function info(){
echo "please like this:\t ./create_git_repo.sh test_project\n"
echo "test_project is you want created project! "
}
#update git conf for add project
#未增加git 操作失败回退,以及未安装git时的提示
function update_git_conf(){
content="\nwritable=$project\nmembers=gavingeng "
#echo -e $content >>/home/gavingeng/tmp/info.log
echo -e $content >>gitosis.conf#echo -e 对于转义字符会做处理
`git add .`
`git commit -m "add project :$PROJECT"`
`git push`
#`git log`
sleep 2
}
#创建git项目,并提交到git 管理
function create_project(){
`cd $PROJECTS_DIR`
mkdir $PROJECTS_DIR$project
cd $PROJECTS_DIR$project
`git init`
`echo "init file" >init.txt`
`git add .`
`git commit -a -m "init repo:$project"`
`git push origin master:refs/heads/master`
#wiki上我写的那几项git操作
}
GIT=`which git`
if [ -z $GIT ];then
echo "please install git; git link:http://xx.xx.xx/download.html"
exit 0
fi
#这里可以采用$1参数来做
cd $GIT_PROJECT_DIR
if [ -z $1 ];then
read project
fi
#回车的判断#
if [ -z $project ];then
echo $project" is empty"
exit 0
fi
if [ -n $project ];then
echo $project
update_git_conf
sleep 2
create_project
else
info
exit 1
fi
以上就是基本的git创建项目操作,或许你有更简洁的书写方式,请回帖!
后续将会再做一些处理。
页:
[1]