diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java index a6f74d24eb..bdbb87f2aa 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java @@ -49,6 +49,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.treewalk.filter.TreeFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import sonia.scm.NotFoundException; import sonia.scm.repository.Changeset; import sonia.scm.repository.ChangesetPagingResult; import sonia.scm.repository.GitChangesetConverter; @@ -206,6 +207,9 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand if (!Strings.isNullOrEmpty(request.getAncestorChangeset())) { ancestorId = repository.resolve(request.getAncestorChangeset()); + if (ancestorId == null) { + throw notFound(entity("Revision", request.getAncestorChangeset()).in(this.repository)); + } } revWalk = new RevWalk(repository); @@ -245,6 +249,8 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand break; } } + } else if (ancestorId != null) { + throw notFound(entity("Revision", request.getBranch()).in(this.repository)); } if (branch != null) { @@ -263,6 +269,10 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand { throw notFound(entity("Revision", e.getObjectId().getName()).in(repository)); } + catch (NotFoundException e) + { + throw e; + } catch (Exception ex) { throw new InternalRepositoryException(repository, "could not create change log", ex); diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandAncestorTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandAncestorTest.java index d36922f941..a2bfa1bd36 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandAncestorTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandAncestorTest.java @@ -35,6 +35,7 @@ package sonia.scm.repository.spi; import org.junit.Test; +import sonia.scm.NotFoundException; import sonia.scm.repository.ChangesetPagingResult; import static org.junit.Assert.assertEquals; @@ -95,6 +96,28 @@ public class GitLogCommandAncestorTest extends AbstractGitCommandTestBase assertEquals("201ecc1131e6b99fb0a0fe9dcbc8c044383e1a07", result.getChangesets().get(6).getId()); } + @Test(expected = NotFoundException.class) + public void testAncestorWithDeletedSourceBranch() + { + LogCommandRequest request = new LogCommandRequest(); + + request.setBranch("no_such_branch"); + request.setAncestorChangeset("master"); + + createCommand().getChangesets(request); + } + + @Test(expected = NotFoundException.class) + public void testAncestorWithDeletedAncestorBranch() + { + LogCommandRequest request = new LogCommandRequest(); + + request.setBranch("b"); + request.setAncestorChangeset("no_such_branch"); + + createCommand().getChangesets(request); + } + private GitLogCommand createCommand() { return new GitLogCommand(createContext(), repository);