tags:

views:

218

answers:

1

I've run into the following issue while trying to execute some git commands from within a Ruby rake task (I've tried without the bash --login -c and get the same result).

tmpid='TueJan26014125UTC2010'
cmd=["git add .",
  "git commit -a -m \'Migrate nanoc3 co output to gh-pages #{tmpid}\'",
  "git push --force origin gh-pages:gh-pages"
]

FileUtils.chdir @gh_pages_repo_path.to_s do
  puts `pwd`
  cmd.each do |cmdi|
      puts "bash --login -c '#{cmdi}'"
      res=Kernel.send(:`, "bash --login -c '#{cmdi}'")
      puts res
    end
end

I this output indicates the working directory and the git push fails

/home/mv/Documents/Workspaces/scar/ruby/scar/gh-pages
bash --login -c 'git add .'

bash --login -c 'git commit -a -m 'Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010''
# On branch master
nothing to commit (working directory clean)
bash --login -c 'git push --force origin gh-pages:gh-pages'
error: src refspec gh-pages does not match any.
error: failed to push some refs to '[email protected]:hedgehog/scar.git'
To prevent you from losing history, non-fast-forward updates were rejected.
Merge the remote changes before pushing again.
See 'non-fast forward' section of 'git push --help' for details.

If I run the same commands, immediately afterwards, from a bash shell (konsole) all proceeds fine:

$ pushd /home/mv/Documents/Workspaces/scar/ruby/scar/gh-pages
/usr/src ~
$ git add .
$ git commit -a -m 'Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010'
[gh-pages 14cbe34] Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010
 20 files changed, 100 insertions(+), 0 deletions(-)
$ git push --force origin gh-pages:gh-pages
Counting objects: 73, done.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (38/38), 11.32 KiB, done.
Total 38 (delta 16), reused 0 (delta 0)
To [email protected]:hedgehog/scar.git
   e0f0370..14cbe34  gh-pages -> gh-pages

Appreciate any insights.

A: 

You might want to try and use a library to handle the git calls for you. One example would be ruby-git.

tadman
Unfortunately I saw this error with ruby-git too which pushed me to use the shell commands. I haven't yet had time to reproduce this, but this seems to have been resolved by running `git branch -a` and `git remote -v` and `git checkout --track -b gh-pages origin/gh-pages` before the `git add`. Then after that the script above worked fine. Again, haven't reproduced this yet... but think it has to do with a state you can get into via Github's recommended way of setting up the gh-pages submodule, i.e. `rm .git/index`, etc.
Hedgehog