* @return a refmodel for the gh-pages branch or null\r
*/\r
public static RefModel getPagesBranch(Repository repository) {\r
- RefModel ghPages = null;\r
+ return getBranch(repository, "gh-pages");\r
+ }\r
+\r
+ /**\r
+ * Returns a RefModel for a specific branch name in the repository. If the\r
+ * branch can not be found, null is returned.\r
+ * \r
+ * @param repository\r
+ * @return a refmodel for the branch or null\r
+ */\r
+ public static RefModel getBranch(Repository repository, String name) {\r
+ RefModel branch = null;\r
try {\r
- // search for gh-pages branch in local heads\r
+ // search for the branch in local heads\r
for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {\r
- if (ref.displayName.endsWith("gh-pages")) {\r
- ghPages = ref;\r
+ if (ref.displayName.endsWith(name)) {\r
+ branch = ref;\r
break;\r
}\r
}\r
\r
- // search for gh-pages branch in remote heads\r
- if (ghPages == null) {\r
+ // search for the branch in remote heads\r
+ if (branch == null) {\r
for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {\r
- if (ref.displayName.endsWith("gh-pages")) {\r
- ghPages = ref;\r
+ if (ref.displayName.endsWith(name)) {\r
+ branch = ref;\r
break;\r
}\r
}\r
}\r
} catch (Throwable t) {\r
- LOGGER.error("Failed to find gh-pages branch!", t);\r
+ LOGGER.error(MessageFormat.format("Failed to find {0} branch!", name), t);\r
}\r
- return ghPages;\r
+ return branch;\r
}\r
\r
/**\r
* @return a refmodel for the ticgit branch or null\r
*/\r
public static RefModel getTicketsBranch(Repository repository) {\r
- RefModel ticgitBranch = null;\r
- try {\r
- // search for ticgit branch in local heads\r
- for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {\r
- if (ref.displayName.endsWith("ticgit")) {\r
- ticgitBranch = ref;\r
- break;\r
- }\r
- }\r
-\r
- // search for ticgit branch in remote heads\r
- if (ticgitBranch == null) {\r
- for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {\r
- if (ref.displayName.endsWith("ticgit")) {\r
- ticgitBranch = ref;\r
- break;\r
- }\r
- }\r
- }\r
- } catch (Throwable t) {\r
- LOGGER.error("Failed to find ticgit branch!", t);\r
- }\r
- return ticgitBranch;\r
+ return JGitUtils.getBranch(repository, "ticgit");\r
}\r
\r
/**\r