提交 a4b46a5c authored 作者: xiaobai's avatar xiaobai

1

上级 e9c4ef79
......@@ -182,32 +182,42 @@ set_branches(){
branch_count=$(echo "$branches" | wc -l)
if [ "$branch_count" -gt 1 ]; then
echo_content "yellow" "$repo_name 项目:分支选择 (如不需要更换直接回车):"
PS3="请输入分支对应的数字:"
# 显示分支列表并允许选择
select branch in $branches; do
# 检查是否直接按回车
if [ -z "$REPLY" ]; then
# 如果按回车不选择,继续使用当前分支
echo_content "yellow" "继续使用当前分支: $current_branch"
branch="$current_branch"
break
elif [ -n "$branch" ]; then
echo_content "green" "你选择了分支: $branch"
# 显示分支列表
i=1
for branch in $branches; do
echo "$i) $branch"
i=$((i + 1))
done
# 提示用户选择
read -p "请输入分支对应的数字 (回车保持当前分支: $current_branch): " input
# 如果用户直接按回车,保持当前分支
if [ -z "$input" ]; then
echo_content "yellow" "继续使用当前分支: $current_branch"
branch="$current_branch"
else
# 验证输入是否为有效的数字
if [[ "$input" =~ ^[0-9]+$ ]] && (( input >= 1 && input <= branch_count )); then
selected_branch=$(echo "$branches" | sed -n "${input}p")
echo_content "green" "你选择了分支: $selected_branch"
# 切换到选定分支
if git show-ref --verify --quiet "refs/heads/$branch"; then
git checkout "$branch" # 切换到本地分支
if git show-ref --verify --quiet "refs/heads/$selected_branch"; then
git checkout "$selected_branch" # 切换到本地分支
else
git checkout -b "$branch" "origin/$branch" # 从远程分支创建并切换
git checkout -b "$selected_branch" "origin/$selected_branch" # 从远程分支创建并切换
fi
break
else
echo_content "red" "无效的选择,请重新输入。"
echo_content "red" "无效的输入,请重新运行脚本。"
exit 1
fi
done
fi
fi
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论