为什么我的git没有自动更新Expect脚本? [英] Why doesn't my git auto-update Expect script work?

查看:647
本文介绍了为什么我的git没有自动更新Expect脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只需要输入我的用户名和我的密码,脚本就可以运行了。

我想创建一个脚本来更新我所有的GitHub仓库。通过一个存储库列表,调用 git push 并通过补充Expect脚本提供必要的信息。



这是我的bash脚本:

 #! / bin / bash 

echo从project_list.txt更新GitHub项目。
echo

read -pGitHub username:un
read -pGitHub密码:-s pw

echo
echo

,而读行
do
eval dir = $ line
echoUpdating:$ dir。
cd $ dir
$ SF / githubexpect $ un $ pw
echo
echo
完成< $ SF / project_list.txt

$ SF 是一个全局环境变量,它包含我的脚本文件夹的绝对路径。



以下是githubexpect脚本:

 #! / usr / bin / expect 

set un [lindex $ argv 0]
set pw [lindex $ argv 1]
$ b $ spawn git push

期望用户名
发送$ un\\\


期望密码
发送$ pw\\\



$ b
$ b 当我运行bash脚本时, li>提示输入信息。
  • 脚本成功启动并继续阅读 project_list.txt 文件。

  • 一旦它发现自己位于版本库的目录中,它就会调用githubexpect脚本,并正确传递信息(我已经测试了这个)。

  • githubexpect正确地产生了 git push

  • 它被提示输入(我在控制台中看到了这个) li>
  • 它确实提供了我的信息(同样,我也看到了这一点)。
  • 然后它继续到下一个存储库,就像什么都没有发生。 < - li>


  • 我怀疑githubexpect脚本可能产卵 git push 相对于自身,而不是当前脚本正在执行的目录,所以git甚至找不到存储库。这可能是错误的,因为我的githubexpect驻留的脚本文件夹也是一个仓库。

    你应该发送 \r 而不是 \\\
    。然而,真正的问题是你不要等待 git push 来完成。将此添加为期望脚本的最后一行

      expect eof 


    I wanted to make a script that would update all of my GitHub repositories.

    I would just need to enter my Username and my Password, and the script would go through a list of repositories, call git push and provide the necessary information via a supplementary Expect script.

    This is my bash script:

    #! /bin/bash
    
    echo "Updating GitHub projects from project_list.txt."
    echo
    
    read -p "GitHub username: " un
    read -p "GitHub password: " -s pw
    
    echo
    echo
    
    while read line
    do
        eval dir=$line
        echo "Updating:" $dir"."
        cd $dir
        $SF/githubexpect $un $pw
        echo
        echo
    done < $SF/project_list.txt
    

    $SF is a global environment variable that contains an absolute path to my script folder.

    Here is the githubexpect script:

    #! /usr/bin/expect
    
    set un [lindex $argv 0]
    set pw [lindex $argv 1]
    
    spawn git push
    
    expect "Username"
    send $un\n
    
    expect "Password"
    send $pw\n
    

    When I run the bash script, things go as expected.

    1. I am prompted for the info.
    2. The script successfully starts and continues reading the project_list.txt file.
    3. Once it finds itself in the repository's directory, it calls the githubexpect script and correctly passes on the info (I've tested this).
    4. githubexpect correctly spawns git push.
    5. It gets prompted for the input (I saw this in the console).
    6. It does provide my info (again, I saw this too).
    7. Then it just continues on to the next repository like nothing happened. <-- Error!

    I am suspecting that the githubexpect script might be spawning git push relative to itself, and not the directory the current script is being executed in, so git doesn't even find a repository. This is probably false though as my script folder, in which githubexpect resides, is a repository as well.

    解决方案

    You should be sending \r instead of \n. However the real problem is you don't wait for git push to complete. Add this as the last line of the expect script

    expect eof
    

    这篇关于为什么我的git没有自动更新Expect脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆