【发布时间】:2013-01-02 23:49:25
【问题描述】:
寻求实现以下目标的解决方案:
- 如果当前未在本地创建上创建分支
- 如果已存在提示用户并移至下一条语句
到目前为止,我已经让它工作了,但还没有完全到位。我的问题确实是后者,但我想花点时间重新思考整个事情,并就如何更合理地写出一些反馈。
变量 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
}
【问题讨论】: