summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/utils/JGitUtils.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2012-01-09 21:10:27 -0500
committerJames Moger <james.moger@gitblit.com>2012-01-09 21:10:27 -0500
commitcc1cd7800940f98efe206fe50a4375a3fb9dc621 (patch)
tree5eb6dd864650ecc5aca016624354fb562623689f /src/com/gitblit/utils/JGitUtils.java
parentd25c599b9967549fe0ebc7a56ca785c317ba3d4b (diff)
downloadgitblit-cc1cd7800940f98efe206fe50a4375a3fb9dc621.tar.gz
gitblit-cc1cd7800940f98efe206fe50a4375a3fb9dc621.zip
Refactored named branch retrieval function
Diffstat (limited to 'src/com/gitblit/utils/JGitUtils.java')
-rw-r--r--src/com/gitblit/utils/JGitUtils.java31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index ae53c942..2a99c973 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -1291,29 +1291,40 @@ public class JGitUtils {
* @return a refmodel for the gh-pages branch or null
*/
public static RefModel getPagesBranch(Repository repository) {
- RefModel ghPages = null;
+ return getBranch(repository, "gh-pages");
+ }
+
+ /**
+ * Returns a RefModel for a specific branch name in the repository. If the
+ * branch can not be found, null is returned.
+ *
+ * @param repository
+ * @return a refmodel for the branch or null
+ */
+ public static RefModel getBranch(Repository repository, String name) {
+ RefModel branch = null;
try {
- // search for gh-pages branch in local heads
+ // search for the branch in local heads
for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {
- if (ref.displayName.endsWith("gh-pages")) {
- ghPages = ref;
+ if (ref.displayName.endsWith(name)) {
+ branch = ref;
break;
}
}
- // search for gh-pages branch in remote heads
- if (ghPages == null) {
+ // search for the branch in remote heads
+ if (branch == null) {
for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {
- if (ref.displayName.endsWith("gh-pages")) {
- ghPages = ref;
+ if (ref.displayName.endsWith(name)) {
+ branch = ref;
break;
}
}
}
} catch (Throwable t) {
- LOGGER.error("Failed to find gh-pages branch!", t);
+ LOGGER.error(MessageFormat.format("Failed to find {0} branch!", name), t);
}
- return ghPages;
+ return branch;
}
/**