mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
use always the branch informations from the receivecommand
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import org.eclipse.jgit.diff.DiffEntry;
|
||||
@@ -134,7 +135,6 @@ public class GitChangesetConverter implements Closeable
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param commit
|
||||
*
|
||||
* @return
|
||||
@@ -142,6 +142,42 @@ public class GitChangesetConverter implements Closeable
|
||||
* @throws IOException
|
||||
*/
|
||||
public Changeset createChangeset(RevCommit commit) throws IOException
|
||||
{
|
||||
List<String> branches = Lists.newArrayList();
|
||||
Set<Ref> refs = repository.getAllRefsByPeeledObjectId().get(commit.getId());
|
||||
|
||||
if (Util.isNotEmpty(refs))
|
||||
{
|
||||
|
||||
for (Ref ref : refs)
|
||||
{
|
||||
String branch = GitUtil.getBranch(ref);
|
||||
|
||||
if (branch != null)
|
||||
{
|
||||
branches.add(branch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return createChangeset(commit, branches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param commit
|
||||
* @param branches
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public Changeset createChangeset(RevCommit commit, List<String> branches)
|
||||
throws IOException
|
||||
{
|
||||
String id = commit.getId().abbreviate(idLength).name();
|
||||
List<String> parentList = null;
|
||||
@@ -183,22 +219,7 @@ public class GitChangesetConverter implements Closeable
|
||||
changeset.getTags().addAll(tagCollection);
|
||||
}
|
||||
|
||||
Set<Ref> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
changeset.setBranches(branches);
|
||||
|
||||
return changeset;
|
||||
}
|
||||
|
||||
@@ -99,13 +99,14 @@ public class GitHookChangesetCollector
|
||||
org.eclipse.jgit.lib.Repository repository = rpack.getRepository();
|
||||
|
||||
RevWalk walk = null;
|
||||
|
||||
|
||||
GitChangesetConverter converter = null;
|
||||
|
||||
try
|
||||
{
|
||||
walk = rpack.getRevWalk();
|
||||
converter = new GitChangesetConverter(repository, walk, GitUtil.ID_LENGTH);
|
||||
converter = new GitChangesetConverter(repository, walk,
|
||||
GitUtil.ID_LENGTH);
|
||||
|
||||
for (ReceiveCommand rc : receiveCommands)
|
||||
{
|
||||
@@ -159,28 +160,19 @@ public class GitHookChangesetCollector
|
||||
|
||||
RevCommit commit = walk.next();
|
||||
|
||||
List<String> branches = Lists.newArrayList(branch);
|
||||
|
||||
while (commit != null)
|
||||
{
|
||||
|
||||
// parse commit body to avoid npe
|
||||
walk.parseBody(commit);
|
||||
Changeset changeset = converter.createChangeset(commit);
|
||||
|
||||
List<String> branches = changeset.getBranches();
|
||||
Changeset changeset = converter.createChangeset(commit, branches);
|
||||
|
||||
if (branches.isEmpty())
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
//J-
|
||||
logger.trace(
|
||||
"missing branch informations for {}, set default branch {}",
|
||||
changeset.getId(),
|
||||
branch
|
||||
);
|
||||
//J+
|
||||
}
|
||||
|
||||
branches.add(branch);
|
||||
logger.trace("retrive commit {} for hook", changeset.getId());
|
||||
}
|
||||
|
||||
changesets.add(changeset);
|
||||
|
||||
Reference in New Issue
Block a user