mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-05 04:55:50 +01:00
return null if commit was not merged into requested branch
This commit is contained in:
@@ -132,13 +132,16 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
{
|
||||
converter = new GitChangesetConverter(gr, revWalk);
|
||||
|
||||
if (request != null &&
|
||||
!Strings.isNullOrEmpty(request.getBranch()) &&
|
||||
revWalk.isMergedInto(commit, findTipCommitForRequestBranch(request, gr, revWalk))) {
|
||||
changeset = converter.createChangeset(commit, request.getBranch());
|
||||
if (isBranchRequested(request)) {
|
||||
String branch = request.getBranch();
|
||||
if (isMergedIntoBranch(gr, revWalk, commit, branch)) {
|
||||
logger.trace("returning commit {} with branch {}", commit.getId(), branch);
|
||||
changeset = converter.createChangeset(commit, branch);
|
||||
} else {
|
||||
logger.debug("returning null, because commit {} was not merged into branch {}", commit.getId(), branch);
|
||||
}
|
||||
} else {
|
||||
changeset = converter.createChangeset(commit);
|
||||
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
@@ -165,8 +168,16 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
return changeset;
|
||||
}
|
||||
|
||||
private RevCommit findTipCommitForRequestBranch(LogCommandRequest request, Repository gr, RevWalk revWalk) throws IOException {
|
||||
return revWalk.parseCommit(GitUtil.getCommit(gr, revWalk, gr.findRef(request.getBranch())));
|
||||
private boolean isMergedIntoBranch(Repository repository, RevWalk revWalk, RevCommit commit, String branchName) throws IOException {
|
||||
return revWalk.isMergedInto(commit, findHeadCommitOfBranch(repository, revWalk, branchName));
|
||||
}
|
||||
|
||||
private boolean isBranchRequested(LogCommandRequest request) {
|
||||
return request != null && !Strings.isNullOrEmpty(request.getBranch());
|
||||
}
|
||||
|
||||
private RevCommit findHeadCommitOfBranch(Repository repository, RevWalk revWalk, String branchName) throws IOException {
|
||||
return revWalk.parseCommit(GitUtil.getCommit(repository, revWalk, repository.findRef(branchName)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -208,8 +208,14 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
GitLogCommand command = createCommand();
|
||||
Changeset c = command.getChangeset("435df2f061add3589cb3", request);
|
||||
|
||||
Assertions.assertThat(c.getBranches().contains("master")).isTrue();
|
||||
Assertions.assertThat(c.getBranches().size()).isEqualTo(1);
|
||||
Assertions.assertThat(c.getBranches()).containsOnly("master");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReturnCommitFromDifferentBranch() {
|
||||
when(request.getBranch()).thenReturn("master");
|
||||
Changeset changeset = createCommand().getChangeset("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", request);
|
||||
Assertions.assertThat(changeset).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user