Search in sources :

Example 1 with IGitCoreLocalBranchSnapshot

use of com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveParentAwareForkPointUnitTestSuite method parentIsNotAncestorOfForkPointAndParentIsAncestorOfChild.

@Test
@SneakyThrows
public void parentIsNotAncestorOfForkPointAndParentIsAncestorOfChild() {
    // given
    IGitCoreCommit forkPointCommit = createGitCoreCommit();
    IGitCoreCommit parentCommit = createGitCoreCommit();
    IGitCoreCommit childCommit = createGitCoreCommit();
    IGitCoreLocalBranchSnapshot parentBranch = createGitCoreLocalBranch(parentCommit);
    IGitCoreLocalBranchSnapshot childBranch = createGitCoreLocalBranch(childCommit);
    PowerMockito.doReturn(Stream.of(forkPointCommit)).when(gitCoreRepository).ancestorsOf(childCommit);
    PowerMockito.doReturn(false).when(gitCoreRepository).isAncestorOrEqual(parentCommit, forkPointCommit);
    PowerMockito.doReturn(true).when(gitCoreRepository).isAncestorOrEqual(parentCommit, childCommit);
    // when
    Option<IGitCoreCommit> result = invokeDeriveParentAwareForkPoint(childBranch, parentBranch);
    // then
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(parentCommit, result.get());
}
Also used : IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with IGitCoreLocalBranchSnapshot

use of com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveSyncToParentStatusUnitTestSuite method branchAndParentPointingSameCommitAndBranchNotJustCreated_merged.

@Test
public void branchAndParentPointingSameCommitAndBranchNotJustCreated_merged() {
    // given
    IGitCoreCommit commit = createGitCoreCommit();
    IGitCoreLocalBranchSnapshot parentBranch = createGitCoreLocalBranch(commit);
    IGitCoreLocalBranchSnapshot childBranch = createGitCoreLocalBranch(commit, new TestGitCoreReflogEntry());
    // when
    SyncToParentStatus syncToParentStatus = invokeDeriveSyncToParentStatus(childBranch, parentBranch, MISSING_FORK_POINT);
    // then
    Assert.assertEquals(SyncToParentStatus.MergedToParent, syncToParentStatus);
}
Also used : TestGitCoreReflogEntry(com.virtuslab.gitmachete.backend.unit.UnitTestUtils.TestGitCoreReflogEntry) IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) SyncToParentStatus(com.virtuslab.gitmachete.backend.api.SyncToParentStatus) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) Test(org.junit.Test)

Example 3 with IGitCoreLocalBranchSnapshot

use of com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveSyncToParentStatusUnitTestSuite method branchPointedCommitIsAncestorOfParentPointedCommit_merged.

@Test
@SneakyThrows
public void branchPointedCommitIsAncestorOfParentPointedCommit_merged() {
    // given
    IGitCoreCommit childCommit = createGitCoreCommit();
    IGitCoreCommit parentCommit = createGitCoreCommit();
    IGitCoreLocalBranchSnapshot childBranch = createGitCoreLocalBranch(childCommit);
    IGitCoreLocalBranchSnapshot parentBranch = createGitCoreLocalBranch(parentCommit);
    PowerMockito.doReturn(false).when(gitCoreRepository).isAncestorOrEqual(parentCommit, childCommit);
    PowerMockito.doReturn(true).when(gitCoreRepository).isAncestorOrEqual(childCommit, parentCommit);
    // when
    SyncToParentStatus syncToParentStatus = invokeDeriveSyncToParentStatus(childBranch, parentBranch, MISSING_FORK_POINT);
    // then
    Assert.assertEquals(SyncToParentStatus.OutOfSync, syncToParentStatus);
}
Also used : IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) SyncToParentStatus(com.virtuslab.gitmachete.backend.api.SyncToParentStatus) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with IGitCoreLocalBranchSnapshot

use of com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveSyncToParentStatusUnitTestSuite method branchAndParentPointingSameCommitAndBranchJustCreated_inSync.

@Test
public void branchAndParentPointingSameCommitAndBranchJustCreated_inSync() {
    // given
    IGitCoreCommit commit = createGitCoreCommit();
    IGitCoreLocalBranchSnapshot parentBranch = createGitCoreLocalBranch(commit);
    IGitCoreLocalBranchSnapshot childBranch = createGitCoreLocalBranch(commit);
    // when
    SyncToParentStatus syncToParentStatus = invokeDeriveSyncToParentStatus(childBranch, parentBranch, MISSING_FORK_POINT);
    // then
    Assert.assertEquals(SyncToParentStatus.InSync, syncToParentStatus);
}
Also used : IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) SyncToParentStatus(com.virtuslab.gitmachete.backend.api.SyncToParentStatus) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) Test(org.junit.Test)

Example 5 with IGitCoreLocalBranchSnapshot

use of com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class UnitTestUtils method createGitCoreLocalBranch.

@SneakyThrows
static IGitCoreLocalBranchSnapshot createGitCoreLocalBranch(IGitCoreCommit pointedCommit, IGitCoreReflogEntry... reflogEntries) {
    IGitCoreLocalBranchSnapshot mock = PowerMockito.mock(IGitCoreLocalBranchSnapshot.class);
    PowerMockito.doReturn(String.valueOf(counter.incrementAndGet())).when(mock).getFullName();
    PowerMockito.doReturn(pointedCommit).when(mock).getPointedCommit();
    PowerMockito.doReturn(List.ofAll(Stream.of(reflogEntries))).when(mock).getReflogFromMostRecent();
    PowerMockito.doReturn(Option.none()).when(mock).getRemoteTrackingBranch();
    return mock;
}
Also used : IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) SneakyThrows(lombok.SneakyThrows)

Aggregations

IGitCoreLocalBranchSnapshot (com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot)13 IGitCoreCommit (com.virtuslab.gitcore.api.IGitCoreCommit)11 SneakyThrows (lombok.SneakyThrows)10 Test (org.junit.Test)9 SyncToParentStatus (com.virtuslab.gitmachete.backend.api.SyncToParentStatus)6 ToString (lombok.ToString)3 lombok.val (lombok.val)3 GitCoreCannotAccessGitDirectoryException (com.virtuslab.gitcore.api.GitCoreCannotAccessGitDirectoryException)2 GitCoreException (com.virtuslab.gitcore.api.GitCoreException)2 GitCoreNoSuchRevisionException (com.virtuslab.gitcore.api.GitCoreNoSuchRevisionException)2 GitCoreRelativeCommitCount (com.virtuslab.gitcore.api.GitCoreRelativeCommitCount)2 GitCoreRepositoryState (com.virtuslab.gitcore.api.GitCoreRepositoryState)2 IGitCoreHeadSnapshot (com.virtuslab.gitcore.api.IGitCoreHeadSnapshot)2 IGitCoreReflogEntry (com.virtuslab.gitcore.api.IGitCoreReflogEntry)2 IGitCoreRepository (com.virtuslab.gitcore.api.IGitCoreRepository)2 BranchFullNameUtils.getLocalBranchFullName (com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getLocalBranchFullName)2 BranchFullNameUtils.getRemoteBranchFullName (com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getRemoteBranchFullName)2 API.$ (io.vavr.API.$)2 Case (io.vavr.API.Case)2 Match (io.vavr.API.Match)2