1

I have the following setup concerning Git:

  • A small server running Arch Linux and the default Git client. I have this setup to automatically make changes to certain files and then push those changes to my Github repository.
  • My Windows 8.1 PC with SmartGit installed. I occasionally make changes to files that I then manually push to my Github repository.

The problem I am having is that when I make some changes to the files on my Windows PC then push those changes, my Arch Linux server apparently loses the ability to push it's changes to the remote repository. The Arch Linux client is able to push it's automated changes without problem up until I push something with the Windows PC. Something breaks after that happens. The only way I've found that fixes this problem is to delete the local repository on my Arch Linux server and then create a new local repository by pulling from the remote.

I scripted the Arch Linux client to pull and fetch from the remote repository before making any changes and I do the same when I make changes on my PC.

Please can someone help me figure out why this is happening and what I can do to stop this problem from occurring in future? Help will be greatly appreciated.

Here are the scripts I am using on my Arch Linux server:

Main script:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

# Test if an internet connection is present
ping -c 3 google.com > /dev/null 2> /dev/null
if [ $? != 0 ]; then
        exit 1
fi

# Git requires that the working directory be the repository I am working with
cd /home/git-user/repositories/xjdhdr-random-code

# Update local repository to ensure no conflicts exist before I make changes
/home/git-user/bin/expect-gitpull.sh

# snip: Everything between these two commands basically make a lot of changes to a lot of text files. Probably has nothing to do with Git or my problem.

# Commit changes to remote repository.
cd /home/git-user/repositories/xjdhdr-random-code
git add -A -f --ignore-errors --
git commit -m "Automatic commit of machine generated changes to repository" --no-edit --


/home/git-user/bin/expect-gitpush.sh

exit 0

/home/git-user/bin/expect-gitpull.sh

#!/bin/expect

set password {*don't need anyone to see my passphrase*}

cd /home/git-user/repositories/xjdhdr-random-code

spawn git pull origin

expect "Enter passphrase for key '/home/git-user/.ssh/id_rsa':"

send -- "$password\r"

send -- "\r"

expect "%PROMPT%"

spawn git fetch -p origin

expect "Enter passphrase for key '/home/git-user/.ssh/id_rsa':"

send -- "$password\r"

send -- "\r"

expect "%PROMPT%"

/home/git-user/bin/expect-gitpush.sh

#!/bin/expect

set password {*ditto*}

cd /home/git-user/repositories/xjdhdr-random-code

spawn git push --recurse-submodules=check

expect "Enter passphrase for key '/home/git-user/.ssh/id_rsa':"

send -- "$password\r"

send -- "\r"

expect "%PROMPT%"
4
  • Btw: You can remove the SSH key's password, removing the need for this... monstrosity. And then, you need to look at the output of a failing push.
    – Daniel B
    Commented Sep 6, 2015 at 10:06
  • Following your advice, I managed to figure out why my scripts weren't working. I noted the reason below.
    – XJDHDR
    Commented Sep 6, 2015 at 12:53
  • And as for the SSH key and passphrases, I could have created it without a passphrase but the documentation I read advised against it.
    – XJDHDR
    Commented Sep 6, 2015 at 13:34
  • Doesn’t make much of a difference if you need to store the password anyway for scripting.
    – Daniel B
    Commented Sep 6, 2015 at 14:42

1 Answer 1

0

I figured out what the problem is. By default, expect is set so that any Expect commands timeout after 10 seconds if a string they were asked to wait for doesn't appear. In my case, the expect "%PROMPT%" was timing out while the "git push" command was running. And since there were no other commands afterwards, the script was terminated. This meant that the push couldn't complete successfully.

The solution is to add set timeout X near the top of the script, replacing X with the number of seconds you want Expect to wait (or use -1 if you want it to wait indefinitely).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .