寻求解决方案以实现以下目标:
- 如果当前未在本地创建上创建分支
- 如果它已经存在提示用户并移动到下一条语句
到目前为止,我已经让它工作了,但并不完全在那里。我的问题确实是后者,但我想花点时间重新思考整个事情,并获得一些关于如何更合理地写这个的反馈。
当分支存在时,该变量existing_branch
提供SHA和refs/heads/branchName,否则 git 会占据并提供预期的fatal:
check_for_branch() {
args=("$@")
echo `$branch${args[0]}`
existing_branch=$?
}
create_branch() {
current="git rev-parse --abbrev-ref HEAD"
branch="git show-ref --verify refs/heads/"
args=("$@")
branch_present=$(check_for_branch ${args[0]})
echo $branch_present
read -p "Do you really want to create branch $1 " ans
case $ans in
y | Y | yes | YES | Yes)
if [ ! -z branch_present ]; then
echo "Branch already exists"
else
`git branch ${args[0]}`
echo "Created ${args[0]} branch"
fi
;;
n | N | no | NO | No)
echo "exiting"
;;
*)
echo "Enter something I can work with y or n."
;;
esac
}