From 11924dc5db4bc44cb32e905700a8557124b1fd56 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 09 Jan 2012 20:49:34 -0500
Subject: [PATCH] Support for gh-pages branch serving as /pages/repo.git

---
 src/com/gitblit/utils/JGitUtils.java |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index d694ee2..ae53c94 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -1284,6 +1284,39 @@
 	}
 
 	/**
+	 * Returns a RefModel for the gh-pages branch in the repository. If the
+	 * branch can not be found, null is returned.
+	 * 
+	 * @param repository
+	 * @return a refmodel for the gh-pages branch or null
+	 */
+	public static RefModel getPagesBranch(Repository repository) {
+		RefModel ghPages = null;
+		try {
+			// search for gh-pages branch in local heads
+			for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {
+				if (ref.displayName.endsWith("gh-pages")) {
+					ghPages = ref;
+					break;
+				}
+			}
+
+			// search for gh-pages branch in remote heads
+			if (ghPages == null) {
+				for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {
+					if (ref.displayName.endsWith("gh-pages")) {
+						ghPages = ref;
+						break;
+					}
+				}
+			}
+		} catch (Throwable t) {
+			LOGGER.error("Failed to find gh-pages branch!", t);
+		}
+		return ghPages;
+	}
+
+	/**
 	 * Returns the list of notes entered about the commit from the refs/notes
 	 * namespace. If the repository does not exist or is empty, an empty list is
 	 * returned.

--
Gitblit v1.9.1