diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java index 39d0f31066..c158dd5d4e 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java @@ -40,6 +40,7 @@ import com.google.common.collect.Multimap; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevWalk; @@ -59,6 +60,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; /** * @@ -99,6 +101,7 @@ public class GitChangesetConverter implements Closeable public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository, RevWalk revWalk, int idLength) { + this.repository = repository; this.idLength = idLength; if (revWalk == null) @@ -175,6 +178,23 @@ public class GitChangesetConverter implements Closeable changeset.getTags().addAll(tagCollection); } + Set refs = repository.getAllRefsByPeeledObjectId().get(commit.getId()); + + if (Util.isNotEmpty(refs)) + { + + for (Ref ref : refs) + { + String branch = GitUtil.getBranch(ref); + + if (branch != null) + { + changeset.getBranches().add(branch); + } + } + + } + return changeset; } @@ -285,6 +305,9 @@ public class GitChangesetConverter implements Closeable /** Field description */ private int idLength; + /** Field description */ + private org.eclipse.jgit.lib.Repository repository; + /** Field description */ private RevWalk revWalk; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitUtil.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitUtil.java index 5c8da91101..571028500c 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitUtil.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitUtil.java @@ -78,6 +78,9 @@ public class GitUtil /** Field description */ public static final String REF_MASTER = "master"; + /** Field description */ + private static final String PREFIX_HEADS = "refs/heads/"; + /** Field description */ private static final String PREFIX_TAG = "refs/tags/"; @@ -209,6 +212,28 @@ public class GitUtil //~--- get methods ---------------------------------------------------------- + /** + * Method description + * + * + * @param ref + * + * @return + */ + public static String getBranch(Ref ref) + { + String branch = null; + + String name = ref.getName(); + + if (name.startsWith(PREFIX_HEADS)) + { + branch = name.substring(PREFIX_HEADS.length()); + } + + return branch; + } + /** * Method description * @@ -239,6 +264,43 @@ public class GitUtil return branchId; } + /** + * Method description + * + * + * @param repository + * @param revWalk + * @param ref + * + * @return + * + * @throws IOException + */ + public static RevCommit getCommit(org.eclipse.jgit.lib.Repository repository, + RevWalk revWalk, Ref ref) + throws IOException + { + RevCommit commit = null; + ObjectId id = ref.getPeeledObjectId(); + + if (id == null) + { + id = ref.getObjectId(); + } + + if (id != null) + { + if (revWalk == null) + { + revWalk = new RevWalk(repository); + } + + commit = revWalk.parseCommit(id); + } + + return commit; + } + /** * Method description * @@ -350,41 +412,4 @@ public class GitUtil return name; } - - /** - * Method description - * - * - * @param repository - * @param revWalk - * @param ref - * - * @return - * - * @throws IOException - */ - public static RevCommit getCommit( - org.eclipse.jgit.lib.Repository repository, RevWalk revWalk, Ref ref) - throws IOException - { - RevCommit commit = null; - ObjectId id = ref.getPeeledObjectId(); - - if (id == null) - { - id = ref.getObjectId(); - } - - if (id != null) - { - if (revWalk == null) - { - revWalk = new RevWalk(repository); - } - - commit = revWalk.parseCommit(id); - } - - return commit; - } }