[Title] Fixed remote build to work even when the git cache is corruppted
authordonghee yang <donghee.yang@samsung.com>
Thu, 29 Nov 2012 08:03:49 +0000 (17:03 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Thu, 29 Nov 2012 08:03:49 +0000 (17:03 +0900)
src/build_server/GitBuildJob.rb

index adb8dc7ae1631e87864206333193d5ec359d15e9..978e016deda7f31e8e7d11770cde9ea84f426789 100644 (file)
@@ -54,7 +54,7 @@ class GitBuildJob < BuildJob
                        @log.error( "Job is stopped by ERROR" , Log::LV_USER)
                        @server.cleaner.clean_afterwards(@id)
                elsif @status == "CANCELED" then
-                       if not @log.nil? then then
+                       if not @log.nil? then
                                @log.error( "Job is CANCELED" , Log::LV_USER)
                        end
                        @server.cleaner.clean_afterwards(@id)
@@ -222,12 +222,24 @@ class GitBuildJob < BuildJob
                        FileUtils.mkdir_p cache_path
                end
 
-               # check branch name
+               # verify git & check branch name
                if File.exist? git_path then
-                       current_branch =  git_cmd_return( "branch",  git_path).select{|x| x.start_with?("*")}[0].split(" ")[1].strip
-                       if current_branch != @git_branch then
-                               @log.warn( "Branch name is changed.", Log::LV_USER)
+                       std_out_lines = git_cmd_return( "branch",  git_path)
+                       if std_out_lines.nil? then 
+                               @log.warn( "Git cache is corrupted! : #{@project.name}", Log::LV_USER)
                                FileUtils.rm_rf git_path
+                       else
+                               branch_list = std_out_lines.select{|x| x.start_with?("*")}
+                               if branch_list.count == 0 then
+                                       @log.warn( "Git cache is corrupted! : #{@project.name}", Log::LV_USER)
+                                       FileUtils.rm_rf git_path
+                               else
+                                       current_branch = branch_list[0].split(" ")[1].strip
+                                       if current_branch != @git_branch then
+                                               @log.warn( "Branch name is changed.", Log::LV_USER)
+                                               FileUtils.rm_rf git_path
+                                       end
+                               end
                        end
                end