#!/usr/bin/bash
function echoError {
echo -e "\033[31m $1 \033[0m"
}
function echoSuccess {
echo -e "\033[32m $1 \033[0m"
}
function echoWarning {
echo -e "\033[33m $1 \033[0m"
}
function echoNotice {
echo -e "\033[36m $1 \033[0m"
}
function hideCursor {
echo -e "\033[?25l"
}
function showCursor {
echo -e "\033[?25h"
}
function setCursor {
local line=$1
local col=$2
tput cup $line $col
}
function isDirExist {
local dirs=$@
for dir in $dirs
do
if [ -d $dir ]
then
continue
else
echo $dir
break
fi
done
}
function isFileExist {
local files=$@
echo $#
for file in $files
do
if [ -f "$file" ]
then
continue
else
echo $file
break
fi
done
}
function upperFirstChar {
local words=$@
local newWords=""
for word in $words
do
local firstChar=${word:0:1}
local upperChar=${firstChar^^}
local newWord=$upperChar${word:1}
newWords="$newWords $newWord"
done
echo $newWords
}
#!/usr/bin/bash
. ./util/utils.sh
function goDirectory
{
local repoPath=$1
local invalidPath=$(isDirExist "$repoPath")
if [ -n "$invalidPath" ]
then
echoError "=== Error: please check '$invalidPath', it is not exist! ==="
exit
else
cd $repoPath
fi
}
#!/usr/bin/bash
. ./util/utils.sh
function gclone {
local repo=$1
git clone "gitPath/${repo}.git"
}
function restoreBranch {
local currentPwd=$1
local currentBranch=$2
cd $currentPwd
git checkout $currentBranch
}
function getCurrentBranch {
echo $(git symbolic-ref --short HEAD)
}
function isBranchExist {
local branch=$(git branch | grep "$1"$)
if [ -z "$branch" ]
then
echoWarning "=== Error: Branch '$1' is not exist! ==="
return 1
fi
}
function checkClean {
local repo=$1
local isClean=$(git diff)
if [ -z "$isClean" ]
then
echoSuccess "=== Cool! current repo $repo is clean ==="
else
echoError "=== Error: Please make the repo '$repo' to be clean status ==="
exit
fi
}
function checkConflict {
local isConflict=$(git diff)
if [ -z $isConflict ]
then
echoWarning "=== Warning: no conflict!==="
else
echoError "=== Error: merge Branch has conflict! ==="
exit
fi
}
function pullCode {
local releaseBranch=$1
local noCheck=$2
if [ -z "$noCheck" ]
then
isBranchExist "$releaseBranch"
if [ $? -ne 0 ]
then
exit
fi
fi
local currentBranch=$(getCurrentBranch)
if [ $currentBranch != $releaseBranch ]
then
echoWarning "=== warning: switch to branch: $releaseBranch ==="
git checkout "$releaseBranch"
fi
echoWarning "=== warning: began to pull code from $releaseBranch ... ==="
git pull
}
function pushCode {
local branch=$1
local file=$2
local comments=$3
git add -- "$file"
git commit --no-verify -m "$comments"
git push --set-upstream origin $branch
if [ $? -eq 0 ]
then
echoSuccess "=== Success: push code Success! ==="
else
echoError "=== Error: push code Failed! ==="
exit
fi
}
function mergeBranch {
local releaseBranch=$1
local myBranch=$2
isBranchExist "$myBranch"
if [ $? -eq 0 ]
then
echoWarning "=== warning: switch to branch: $myBranch ==="
git checkout "$myBranch"
echoWarning "=== warning: began to merge branch: $releaseBranch to $myBranch ... ==="
git merge "$releaseBranch" --commit "merge $releaseBranch to $myBranch"
else
echoError "=== Error: Please check the myBranch correctly! ==="
exit
fi
}
function createNewBranch {
local baseBranch=$1
local newBranch=$2
isBranchExist "$newBranch"
if [ $? -eq 0 ]
then
echoWarning "=== warning: switch to branch: $newBranch ==="
git checkout "$newBranch"
echoWarning "=== Warning: $newBranch has exist! ==="
else
git checkout "$baseBranch"
echoWarning "=== warning: switch to branch: $newBranch ==="
git checkout -b "$newBranch"
echoSuccess "=== Success: $newBranch create Success! ==="
fi
}
function switchBranch {
local branch=$1
isBranchExist "$branch"
if [ $? -eq 0 ]
then
echoWarning "=== warning: switch to branch: $branch ==="
git checkout "$branch"
else
echoError"=== Error: $branch is not Exist! ==="
exit
fi
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2022-02-14 shell编程 - 条件测试
2022-02-14 shell编程 - 条件语句