package controllers;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import models.Project;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.tmatesoft.svn.core.SVNException;

import play.mvc.Controller;
import play.mvc.Result;
import playRepository.Commit;
import playRepository.RepositoryService;
import utils.RequestUtil;
import views.html.code.history;
import views.html.code.diff;

public class CodeHistoryApp extends Controller {

    private static final int HISTORY_ITEM_LIMIT = 25;

    public static Result history(String userName, String projectName) throws IOException,
            UnsupportedOperationException, ServletException, NoHeadException, GitAPIException,
            SVNException {
        Project project = Project.findByName(projectName);
        String url = CodeApp.getURL(userName, projectName);
        String pageStr = RequestUtil.getFirstValueFromQuery(request().queryString(), "page");
        int page = 0;
        if (pageStr != null) {
            page = Integer.parseInt(pageStr);
        }

        List<Commit> commits = RepositoryService.getRepository(project).getHistory(page,
                HISTORY_ITEM_LIMIT);

        return ok(history.render(url, project, commits, page));
    }

    public static Result show(String userName, String projectName, String commitId)
            throws IOException, UnsupportedOperationException, ServletException, GitAPIException,
            SVNException {
        Project project = Project.findByName(projectName);
        String patch = RepositoryService.getRepository(project).getPatch(commitId);

        return ok(diff.render(project, patch));
    }

}
@@ -461,16 +461,47 @@
 istory;%0A
+import views.html.code.nohead;%0A
 import v
@@ -521,16 +521,16 @@
 e.diff;%0A
-
 %0Apublic 
@@ -781,25 +781,8 @@
 ion,
- NoHeadException,
  Git
@@ -1141,24 +1141,42 @@
 %0A        %7D%0A%0A
+        try %7B%0A    
         List
@@ -1268,16 +1268,20 @@
         
+    
 HISTORY_
@@ -1293,25 +1293,25 @@
 LIMIT);%0A
-%0A
+ 
         
 return o
@@ -1294,32 +1294,35 @@
 IMIT);%0A         
+   
 return ok(histor
@@ -1357,24 +1357,124 @@
 ts, page));%0A
+        %7D catch (NoHeadException e) %7B%0A            return ok(nohead.render(url, project));%0A        %7D%0A
     %7D%0A%0A    p

Add the error handling for NoHeadException.