Why doesn't my git auto-update Expect script work?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 20:43:15

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/14092636/why-doesnt-my-git-auto-update-expect-script-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!