<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -18,6 +18,8 @@ TRUNK
 - [bugfix] Make dashboard xhtml compliant
 - [bugfix] Recognize OpenBSD as a platform
 - Improve daemon_helper to kill all child processes (don't leave any orphans)
+- [bugfix] Timeout if 'git fetch origin' hangs.  Configurable via git_load_new_changesets_timeout.
+           Fixes https://cruisecontrolrb.lighthouseapp.com/projects/9150-cruise-control-rb/tickets/229-sometimes-git-hangs
 
 ------------------------------------------------------------------------------------------------------------------------
 * 1.3.0</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -9,12 +9,13 @@ class Configuration
   @disable_build_now = false
   @serialize_builds = false
   @serialized_build_timeout = 1.hour
+  @git_load_new_changesets_timeout = 5.minutes
 
   class &lt;&lt; self
     # published configuration options (mentioned in config/site_config.rb.example)
     attr_accessor :default_polling_interval, :disable_build_now, :email_from,
                   :dashboard_refresh_interval, :serialize_builds,
-                  :serialized_build_timeout
+                  :serialized_build_timeout, :git_load_new_changesets_timeout
     attr_reader :dashboard_url
 
     # non-published configuration options (obscure stuff, mostly useful for http://cruisecontrolrb.thoughtworks.com)</diff>
      <filename>config/configuration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -63,6 +63,9 @@
 # Amount of time a project will wait to build before failing when build serialization is on
 # Configuration.serialized_build_timeout = 3.hours
 
+# Amount of time a project will wait for git to load new changesets before failing
+# Configuration.git_load_new_changesets_timeout = 5.minutes
+
 # To delete build when there are more than a certain number present, uncomment this line - it will make the dashboard 
 # perform better
 # BuildReaper.number_of_builds_to_keep = 20</diff>
      <filename>config/site_config.rb_example</filename>
    </modified>
    <modified>
      <diff>@@ -93,7 +93,12 @@ module SourceControl
     end
 
     def load_new_changesets_from_origin
-      git(&quot;fetch&quot;, [&quot;origin&quot;])
+      Timeout.timeout(Configuration.git_load_new_changesets_timeout, Timeout::Error) do
+        sleep 5
+        git(&quot;fetch&quot;, [&quot;origin&quot;])
+      end
+    rescue Timeout::Error =&gt; e
+      raise BuilderError.new(&quot;Timeout in 'git fetch origin'&quot;)
     end
 
     def git(operation, arguments = [], options = {}, &amp;block)</diff>
      <filename>lib/source_control/git.rb</filename>
    </modified>
    <modified>
      <diff>@@ -77,9 +77,9 @@ class SourceControl::GitTest &lt; Test::Unit::TestCase
   def test_latest_revision_should_call_git_log_and_send_it_to_parser
     in_sandbox do
       git = new_git
+      git.expects(:git).with('fetch', ['origin'])
       git.expects(:git).with(&quot;branch&quot;).yields(StringIO.new(&quot;* master\n&quot;))
       git.expects(:git).with(&quot;log&quot;, [&quot;-1&quot;, '--pretty=raw', &quot;--stat&quot;, 'origin/master']).returns('')
-      git.expects(:git).with('fetch', ['origin'])
       stub_parser = Object.new
       stub_parser.stubs(:parse).returns([:foo])
       Git::LogParser.expects(:new).returns(stub_parser)
@@ -88,6 +88,33 @@ class SourceControl::GitTest &lt; Test::Unit::TestCase
     end
   end
 
+  def test_latest_revision_should_timeout
+    in_sandbox do
+      git = new_git
+      class &lt;&lt; git
+        def git(*args)
+          sleep 1
+        end
+      end
+      
+      begin
+        old_timeout = Configuration.git_load_new_changesets_timeout
+        Configuration.git_load_new_changesets_timeout = 0.5
+
+        assert_raise(BuilderError) do
+          begin
+            git.latest_revision
+          rescue BuilderError =&gt; e
+            assert_equal &quot;Timeout in 'git fetch origin'&quot;, e.message
+            raise e
+          end
+        end
+      ensure
+        Configuration.git_load_new_changesets_timeout = old_timeout
+      end
+    end
+  end
+
   def test_current_branch_should_parse_git_branch_output
     in_sandbox do
       git = new_git</diff>
      <filename>test/unit/source_control/git_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2b03f393005c0c10ed92824a999876d777993730</id>
    </parent>
  </parents>
  <author>
    <name>Chad Woolley &amp; Josh Susser</name>
    <email>thewoolleyman+josh_and_chad@gmail.com</email>
  </author>
  <url>http://github.com/thoughtworks/cruisecontrol.rb/commit/d0319803832321f7b5618344e12af69bc0874ba2</url>
  <id>d0319803832321f7b5618344e12af69bc0874ba2</id>
  <committed-date>2009-05-11T16:35:02-07:00</committed-date>
  <authored-date>2009-05-11T16:35:02-07:00</authored-date>
  <message>Add timeout for git fetch origin.  See https://cruisecontrolrb.lighthouseapp.com/projects/9150-cruise-control-rb/tickets/229-sometimes-git-hangs</message>
  <tree>eb5252cfb5183f6f363ebff5e5802f1417e1eb98</tree>
  <committer>
    <name>Chad Woolley &amp; Josh Susser</name>
    <email>thewoolleyman+josh_and_chad@gmail.com</email>
  </committer>
</commit>
