Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wikinee
V2EX  ›  Linux

写了个 git push 脚本,容易崩溃,有大神给点意见么

  •  
  •   wikinee · Dec 10, 2015 · 4188 views
    This topic created in 3850 days ago, the information mentioned may be changed or developed.
    # !/bin/bash
    # maybe you are using bash,fix the first line.
    # Program:
    # THIS PROGRAM IS FOR GIT PUSH
    # BEFORE USE THIS SCRIPT, YOU MUST ADD YOU GIT PRIVATE KEY,LIKE FOLLOW SHELL COMMAND.
    # ssh-add you_ssh_private_key_path,like ssh-add ~/.ssh_github/id_rsa
    # History:
    # 2015/10 wikinee First release
    # ENV
    # ubuntu 14.04 LTS
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin/:~/bin
    export PATH

    echo "===========git config========="
    echo "Ignore Permission"
    git config core.fileMode false
    echo "===========git branch========="
    git branch
    echo "===========git fetch==========="
    echo "Input destination branch, must be already exist in remote.Enter use master:"
    read to_branch
    echo "Add tmp branch to store diff"
    git fetch origin ${to_branch:=master}:tmp
    echo "This time will modify following:"
    git diff tmp
    read -p "Merge it, y or Y?" yn
    if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
    echo $yn
    echo "now merge it."
    git merge tmp
    else echo "Illeagal Character."
    exit
    fi

    echo "===========git status========="
    git status
    echo "Input git add parameter,like -A"
    read input1
    git add $input1
    echo "===========git commit========="
    read -p "Git commit this changes?(y/n)" yn
    if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
    echo $yn
    echo "Pow you can input commit message:"
    elif [ "$yn" == "N" ]||[ "$yn" == "n" ] ;then
    echo $yn
    echo "Not Committed."
    exit
    else echo "illeagal character."
    exit
    fi
    read input2
    git commit -m "$input2" -a
    echo "===========git push==========="
    echo "Push to git?(y/n)"
    read push_choice
    if [ "$push_choice" == "y" ]||[ "$push_choice" == "Y" ] ;then
    echo "Now push files,you can give parameter 1,default 'origin'."
    read input3
    echo "Now push files,you can give parameter 2,default 'master'."
    read input4
    git push -u $input3 $input4
    else
    echo "Already Commit, But Not Pushed"
    fi
    11 replies    2015-12-11 17:07:09 +08:00
    wlsnx
        1
    wlsnx  
       Dec 10, 2015
    我建议手打这些命令,可以更自由地调整流程,出了问题也容易发现和修改,合并 PR 之前检查清楚。
    wikinee
        2
    wikinee  
    OP
       Dec 10, 2015
    @wlsnx 目前在使用 alias 简化命令, 脚本是更进一步简化
    500miles
        3
    500miles  
       Dec 10, 2015
    太长 太乱 不看 (:教导主任的表情

    哈哈
    spacewander
        4
    spacewander  
       Dec 10, 2015
    崩溃是什么情况?有出错信息吗?
    感觉合并和提交可以分开两个脚本来写。另外没必要每次执行的时候都设置 PATH 和`git config`。
    KyleMeow
        5
    KyleMeow  
       Dec 10, 2015
    至少每步执行后需要判断返回值 $? 是不是 0 才继续下一步吧,不然一步没成,后面都在做无用功
    jackysc
        6
    jackysc  
       Dec 10, 2015
    bash -x 调试吧
    GNiux
        7
    GNiux  
       Dec 10, 2015 via iPhone
    轻轻地说:楼主英语……不敢恭维……蹩脚……如:“ Enter use master ” —— Type Enter to use 'master':"

    另,输入 n N 就是非法字符?
    —— read -p "Merge it, y or Y?" yn
    if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
    echo $yn
    echo "now merge it."
    git merge tmp
    else echo "Illeagal Character."
    darkbill
        8
    darkbill  
       Dec 10, 2015
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin/:~/bin
    export PATH

    我觉得开头的这两行语句的写法,要不得~~
    人家电脑上面还有 /opt/bin 在 path 的怎么办?都被你洗了。
    你要添加~/bin ,可以用字符串连接的方式来添加。。。
    wikinee
        9
    wikinee  
    OP
       Dec 10, 2015   ❤️ 1
    @spacewander 好建议
    @KyleMeow 我现在改成回车就继续,不然就推出
    @jackysc 我说的崩溃是指的情况好复杂,太多种可能了
    @GNiux 能看懂就好了, enlish 不好,又戳我伤心事
    @darkbill path 这两句鸟哥私房菜上抄来的,你一说我都对人生产生怀疑,又去看了一眼,就是这么写的。
    估计应该 PATH=xxx:$PATH
    yzimhao
        10
    yzimhao  
       Dec 11, 2015
    自己撸的一个发布代码工具,增量更新代码
    代码: https://github.com/yzimhao/shellcode/blob/master/issuecode
    说明: https://github.com/yzimhao/shellcode#1-issuecode
    zhouyg
        11
    zhouyg  
       Dec 11, 2015
    建议写成半自动的,经常需要思考的手打,然后固定的操作写成脚本。

    一般而言,当我启动一些脚本时,就等它自动完成就好了。顺便喝口水。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5336 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    ♥ Do have faith in what you're doing.