12月28, 2022

shell脚本实现交互式的删除git远程仓库已发布的tag的脚本

shell脚本实现交互式的删除git远程仓库已发布的tag的脚本

image.png

image.png

image.png

脚本如下

#!/bin/bash

function promptbox() {
    # promptbox <title> [<content> [<height> [<width> [<yes_button> [<no_button>]]]]]
    title=$1
    yesno=$2
    height=10
    width=60
    yes_button="Yes"
    no_button="No"
    if [ -n "$3" ]; then
        height=$3
    fi
    if [ -n "$4" ]; then
        width=$4
    fi
    if [ -n "$5" ]; then
        yes_button=$5
    fi
    if [ -n "$6" ]; then
        no_button=$6
    fi

    # 提示框
    # whiptail --title "<dialog box title>" --yesno "<text to show>" <height> <width>
    #!/bin/bash if (whiptail --title "Test Yes/No Box" --yes-button "Skittles" --no-button "M&M's" --yesno "Which do you like better?" 10 60) then echo "You chose Skittles Exit status was $?." else echo "You chose M&M's. Exit status was $?." fi
    whiptail --title "$title" --yes-button "$yes_button" --no-button "$no_button" --yesno "$yesno" $height $width
    ret=$?
    return $ret
}

scriptPath=$(cd $(dirname $0) && pwd)
cd ${scriptPath}

TagSize=$(git tag -l | wc -l)
TagList=`git tag -l | awk '{for(i=1;i<=NF;i++) printf "%s < ",$1 }'`
echo ${TagList}
changeTagCmd="whiptail --title \"删除Tag脚本\" --ok-button \"确定\" --cancel-button \"取消\" --menu \"请选择要删除的tag值:\" 15 120 ${TagSize} ${TagList}"
TAGNAME=$(${changeTagCmd} 3>&1 1>&2 2>&3) 
exitstatus=$? 
if [ $exitstatus = 0 ]; then 
    echo "Your chosen Tag:" $TAGNAME 
else 
    echo "You chose Cancel." 
    exit 0
fi

promptbox "命令执行" "是否执行命令\"git tag -d ${TAGNAME}\"" 10 120 "是" "否"
ret=$?
if [ $ret = 0 ]; then
    echo "开始执行命令:\"git tag -d ${TAGNAME}\""
    git tag -d ${TAGNAME}
else 
    echo "取消执行" 
    exit 0
fi

promptbox "命令执行" "是否执行命令\"git push origin :refs/tags/${TAGNAME}\"" 10 120 "是" "否"
ret=$?
if [ $ret = 0 ]; then
    echo "开始执行命令:\"git push origin :refs/tags/${TAGNAME}\""
    git push origin :refs/tags/${TAGNAME}
else 
    echo "取消执行" 
    exit 0
fi

exit 0
————————————————
版权声明:本文为CSDN博主「跃龙客」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yjkhtddx/article/details/125406147

本文链接:https://587v5.com/post/shell-jiao-ben-shi-xian-jiao-hu-shi-de-shan-chu-git-yuan-cheng-cang-ku-yi-fa-bu-de-tag-de-jiao-ben.html

Comments