为什么用svn ,并且用命令行版,这个脚本有毛用?
因为一些老项目是svn写的,必须要用这个,为这玩意儿装个gui的东西感觉浪费,这个脚本本来是为了避免commit 的时候commit 当前目录所有文件准备的,因为git
用户不习惯啊,不小心 svn commit
了 就尴尬拉,所以强制后面带文件的方式commit
求助各位英雄如何做?
我将此文件替代原本的svn
用来避免一些可能的错误操作,但是有的地方觉得不是很优雅,因为毕竟写的少,还望各位大佬帮忙优化,感激不尽
#!/bin/bash
#
# @function SVN 提交工具
# @uses /bin/bash
# @version 1.0
# @author Pu ShaoWei
#
# ---------------------------------------------------------------------------------------- #
#
# ├── Patch 配置
# │
# ├── Common
# │
# ├── Fcuntion
# │
# └── Init
# ---------------------------------------------------------------------------------------- #
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin;export PATH
SVN=/usr/bin/svn;
DEPLOY_TOOLS_DIR=`pwd`
# ---------------------------------------- Common ---------------------------------------- #
function validate(){
if [[ $1 == "" || $2 == "" ]]; then
echo "Param Fail"
exit 1;
fi
for var in $*
do
if [[ $var == $1 ]]; then
continue;
fi
if [[ ! -d $DEPLOY_TOOLS_DIR"/"$var ]];then
if [[ ! -f $DEPLOY_TOOLS_DIR"/"$var ]];then
continue;
fi
fi
file_path=$file_path" "$var
done
if [[ $file_path == "" ]]; then
echo "not File"
return 1;
fi
echo $file_path;
}
# ---------------------------------------- Function ---------------------------------------- #
function addCommand(){
file=$(validate $*);
if [[ $? == "1" ]]; then
echo $file
exit $?;
fi
$SVN add $file;
}
function ciCommand()
{
msg=$3;
if [[ $3 == "" ]]; then
echo "Msg Empty!!"
exit 0;
fi
file=$(validate $*);
if [[ $? == "1" ]]; then
echo $file
exit $?;
fi
$SVN commit -m $msg $file;
}
function revCommand()
{
file=$(validate $*);
if [[ $? == "1" ]]; then
echo $file
exit $?;
fi
$SVN revert $file;
}
function logCommand()
{
if [[ $2 != "" ]]; then
$SVN log -v --search $2 | less;
exit;
fi
$SVN log -v | less;
}
function vgCommand()
{
echo '=========================================================================='
echo ' [添加文件] svn add '
echo ' [提交文件] svn commit '
echo ' [详细信息] svn info '
echo ' [更新信息] svn up '
echo ' [删除文件] svn delete '
echo ' [查看日志] svn log '
echo ' [对比文件] svn diff '
echo ' [撤销命令] svn revert '
echo ' [更新冲突]
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options:
解析:
(p) postpone 把服务器代码和自己的代码都显示出来,供我们解决
(df) diff-full 命令行显示冲突内容,不好看
(e) edit 修改,不要这么做
(mc) mine-conflict 只使用自己的代码,删除服务器的
(tc) theirs-conflict 只使用服务器的,删除自己的代码
(s) show all options 再重新打印一下这个选择日志 '
echo '=========================================================================='
}
# ----------------------------------- Init ---------------------------------------- #
case $1 in
add)
addCommand $*
exit $?;
;;
commit)
ciCommand $*
exit $?;
;;
status)
$SVN status;
exit $?;
;;
info)
$SVN info;
exit $?;
;;
checkout)
$SVN checkout $2;
exit $?;
;;
log)
logCommand $*
exit $?;
;;
up)
$SVN up
exit $?;
;;
delete)
$SVN delete $2
exit $?;
;;
diff)
$SVN diff $2
exit $?;
;;
revert)
revCommand $*
exit $?;
;;
vg)
vgCommand $*
exit $?;
;;
*)
vgCommand $*;
exit 1;
esac
写的还可以,说个小优化吧。
你可以把下面的代码单独做成一个函数。
另外一个就是不知道是不是因为你复制过来的原因,缩进有点奇怪。