How to install patches?

Hari Rajagopal wrote:

   Can someone explain how do I install patches.

I can’t believe that a straightforward, reasonable question like this
went unanswered for 2 and a half years. Especially given how little info
there is about applying or installing patches out there.

Anyway, this is how to install/apply patches once you’ve got the .diff
file* downloaded. I don’t know how to do it from repositories, I’m a
newbie too sadly, but hopefully this will be useful to someone.

* note - often patch files are named .dif or .diff, but often they won’t
have any file extension at all. They usually come double-zipped in
.tar.gz despite only being one file.

First, unzip the patch file completely, and put it in the root directory
of your app.

For the next step, you need a bash console – the ones where there is a $
before each input line. This is a unix thing, Linux and Macs come with
them as standard - though I don't know if they have the 'patch' binaries
as standard, sorry.

If you’re using Windows, install CygWin from cygwin.com. Cygwin doesn’t
come with the ‘patch’ binaries package as standard – you need to add it
during the setup process. There’ll be a screen offering you a huge list
of categories of packages. Hit the ‘View’ button to switch to an
alphabetical list of all packages to find 'patch'.

Once you’ve got a bash shell with patch installed, open it, navigate to
your app’s root directory, then do a patch command to apply the patch.
This will usually look like this:-

$ patch -p0 -i name_of_patch_here

I say ‘usually’ because, to be honest, I don’t know what -p0 or -i do,
but it works for me. If that doesn’t work as expected, on one site, I
saw it written this way:-

$ patch -p0 < name_of_patch_here.patch

That should work. I hope this is useful to someone and saves you the
hours it took me to find it all the hard way...

Alan Slater wrote:

Hari Rajagopal wrote:

   Can someone explain how do I install patches.

I can’t believe that a straightforward, reasonable question like this went unanswered for 2 and a half years. Especially given how little info there is about applying or installing patches out there.

Could you please provide a little information on how one submits patches for rails? I've gotten as far as git clone, but then everything goes to hell. (I can be more specific if anyone feels like throwing me a bone.) I've been trying to follow along with this screencast:

http://railscasts.com/episodes/113-contributing-to-rails-with-git

This will usually look like this:-

$ patch -p0 -i name_of_patch_here

I say ‘usually’ because, to be honest, I don’t know what -p0 or -i do, but it works for me.

-p is for stripping leading parts of the path, e.g. -p1 is used to turn absolute paths into relative paths. -p0 should be a no-op. -i means you're going to pass the patch file as an argument, rather than letting the patch program read stdin. The above should be equivalent to:

$ patch < name_of_patch_here

Try this: http://afreshcup.com/2008/10/27/contributing-to-rails-step-by-step/

Colin Law wrote:

Try this: http://afreshcup.com/2008/10/27/contributing-to-rails-step-by-step/

Thanks, that looks promising. Unfortunately, rake self-test fails immediately. Here is the error message, with some path prefixes removed, and lines split for Usenet readability:

$ rake test_sqlite3
(in rails/activerecord)
:0:Warning: Gem::manage_gems is deprecated \
     and will be removed on or after March 2009.
/opt/local/bin/ruby -Ilib:test:test/connections/native_sqlite3\
     [lots of .rb paths elided]
<internal:gem_prelude>:249:in `push_gem_version_on_load_path':\
     undefined method `<=>' for nil:NilClass (NoMethodError)
   from <internal:gem_prelude>:14:in `gem'
   from rails/activerecord/test/cases/helper.rb:8:in `<top (required)>'
   from rails/activerecord/test/cases/aaa_create_tables_test.rb:2:\
       in `require'
   from rails/activerecord/test/cases/aaa_create_tables_test.rb:2:\
       in `<top (required)>'
   from rake-0.8.3/lib/rake/rake_test_loader.rb:5:in `load'
   from rake-0.8.3/lib/rake/rake_test_loader.rb:5:in `block in <main>'
   from rake-0.8.3/lib/rake/rake_test_loader.rb:5:in `each'
         from rake-0.8.3/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!
Command failed with status (1): \
     [/opt/local/bin/ruby -Ilib:test:test/connec...]
(See full trace by running task with --trace)
$

The relevant line (8) in helper.rb looks like this:

gem 'mocha', '>= 0.9.5'

By the way, how does one "create" and empty sqlite3 database? I tried mysql, and it fought me, too. I think part of my problem is that I'm trying to come to grips with OS X (coming from other Unixen) at the same time I'm trying to learn Rails.

I think you need the mocha gem installed. Otherwise I am outside my knowledge base both with sqlite and mac.

Colin Law wrote:

I think you need the mocha gem installed.

Well, holy crap! It's at least getting past that initial error about "undefined method `<=>'". Thanks!

Otherwise I am outside my knowledge base both with sqlite and mac.

FWIW, I tried mysql from MacPorts, and nothing worked with that, either. I'm hitting lots of little, time-consuming, irritating things; e.g. the tutorials all refer to mysql, but MacPorts actually installs it as mysql5.

Jeff Schwab wrote:

Colin Law wrote:

I think you need the mocha gem installed.

Well, holy crap! It's at least getting past that initial error

By the way, do you think this merits a bug report and/or patch?

I found the following similar-but-different ticket:
http://rails.lighthouseapp.com/projects/8994/tickets/186-activerecord-test-failures-when-mocha-is-not-installed