From: David Masover Date: 2011-06-13T05:18:48+09:00 Subject: Re: Interacting with Git On Sunday, June 12, 2011 09:05:27 AM paul h wrote: > Therefore, I need ruby to: > > git pull ... > enter password > wait for git to complete pulling files in > hand control back to the Rails app to analyse the files and perform > any back office processing as I see fit Suggestion: Set up public-key authentication with ssh. If you're paranoid, you could fire up an ssh-agent and do ssh-add while booting the application (requiring you to be there for the boot), but it seems to me that having your Rails app know your ssh password isn't any less dangerous than having an ssh key file somewhere accessible to your Rails app. Then, maybe you want to have Git log stuff, but there's no longer any reason you need to interact with Git other than fire off the command and check the exit code. In other words... > I've been through the Pickaxe book, and am going to look closer at PTY > and the 'expect' method later today and see if I can figure it out > with these... You don't need that, you don't need Grit unless you find it useful for other things. The simplest thing that could work is: if system 'git pull ...' # success else logger.error "git pull failed with exit code #{$?}" end It gets a little more complicated if you need to log the git output from Ruby. I'm sure there's a better way to do this: require 'open3' Open3.popen3 'git pull ...' do |stdin, stdout, stderr, wait_thr| stdin.close threads = [] threads << Thread.new { stdout.each_line { |line| logger.info line } } threads << Thread.new { stderr.each_line { |line| logger.error line } } threads.each(&:join) stdout.close stderr.close if wait_thr.value.success? # success else logger.error "Git pull failed with exit code #{wait_thr.value.exitcode}" end end Finally, you probably want to replace the string 'git pull' with separate string arguments, like: Open3.popen 'git', 'pull', ... Aside from saving you some string concatenation, it also means you don't have to deal with quoting things for the shell.