From 11924dc5db4bc44cb32e905700a8557124b1fd56 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 9 Jan 2012 20:49:34 -0500 Subject: Support for gh-pages branch serving as /pages/repo.git --- src/com/gitblit/utils/JGitUtils.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/com/gitblit/utils/JGitUtils.java') diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index d694ee28..ae53c942 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -1283,6 +1283,39 @@ public class JGitUtils { return list; } + /** + * 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 -- cgit v1.2.3