Search in sources :

Example 1 with IBranchLayoutEntry

use of com.virtuslab.branchlayout.api.IBranchLayoutEntry in project git-machete-intellij-plugin by VirtusLab.

the class BranchLayoutTestSuite method withBranchSlideOut_givenRootBranchWithChildren_slidesOut.

@Test
public void withBranchSlideOut_givenRootBranchWithChildren_slidesOut() {
    // given
    String rootName = "root";
    String childName0 = "child0";
    String childName1 = "child1";
    /*-
            root          slide out
              child0       ----->        child0
              child1                     child1
    */
    List<IBranchLayoutEntry> childBranches = List.of(new BranchLayoutEntry(childName0, /* customAnnotation */
    null, List.empty()), new BranchLayoutEntry(childName1, /* customAnnotation */
    null, List.empty()));
    val entry = new BranchLayoutEntry(rootName, /* customAnnotation */
    null, childBranches);
    val branchLayout = new BranchLayout(List.of(entry));
    // when
    IBranchLayout result = branchLayout.slideOut(rootName);
    // then
    assertEquals(result.getRootEntries().size(), 2);
    assertEquals(result.getRootEntries().get(0).getName(), childName0);
    assertEquals(result.getRootEntries().get(1).getName(), childName1);
}
Also used : lombok.val(lombok.val) BranchLayout(com.virtuslab.branchlayout.api.BranchLayout) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) Test(org.junit.Test)

Example 2 with IBranchLayoutEntry

use of com.virtuslab.branchlayout.api.IBranchLayoutEntry in project git-machete-intellij-plugin by VirtusLab.

the class BranchLayoutFileReader method createEntry.

/**
 * Parses line to {@link BranchLayoutEntry#BranchLayoutEntry} arguments and creates an
 * entry with the specified {@code children}.
 */
private IBranchLayoutEntry createEntry(String line, List<IBranchLayoutEntry> children) {
    LOG.debug(() -> "Entering: line = '${line}', children = ${children}");
    String trimmedLine = line.trim();
    String branchName;
    String customAnnotation;
    int indexOfSpace = trimmedLine.indexOf(' ');
    if (indexOfSpace > -1) {
        branchName = trimmedLine.substring(0, indexOfSpace);
        customAnnotation = trimmedLine.substring(indexOfSpace + 1).trim();
    } else {
        branchName = trimmedLine;
        customAnnotation = null;
    }
    val result = new BranchLayoutEntry(branchName, customAnnotation, children);
    LOG.debug(() -> "Created ${result}");
    return result;
}
Also used : lombok.val(lombok.val) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry)

Example 3 with IBranchLayoutEntry

use of com.virtuslab.branchlayout.api.IBranchLayoutEntry in project git-machete-intellij-plugin by VirtusLab.

the class BranchLayoutTestSuite method withBranchSlideOut_givenDuplicatedBranch_slidesOut.

@Test
public void withBranchSlideOut_givenDuplicatedBranch_slidesOut() {
    // given
    String rootName = "root";
    String branchToSlideOutName = "child";
    /*-
        root                        root
          child      slide out
          child       ----->
    */
    List<IBranchLayoutEntry> childBranches = List.of(new BranchLayoutEntry(branchToSlideOutName, /* customAnnotation */
    null, List.empty()), new BranchLayoutEntry(branchToSlideOutName, /* customAnnotation */
    null, List.empty()));
    val rootEntry = new BranchLayoutEntry(rootName, /* customAnnotation */
    null, childBranches);
    val branchLayout = new BranchLayout(List.of(rootEntry));
    // when
    IBranchLayout result = branchLayout.slideOut(branchToSlideOutName);
    // then
    assertEquals(result.getRootEntries().size(), 1);
    assertEquals(result.getRootEntries().get(0).getName(), rootName);
    val children = result.getRootEntries().get(0).getChildren();
    assertEquals(children.size(), 0);
}
Also used : lombok.val(lombok.val) BranchLayout(com.virtuslab.branchlayout.api.BranchLayout) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) Test(org.junit.Test)

Example 4 with IBranchLayoutEntry

use of com.virtuslab.branchlayout.api.IBranchLayoutEntry in project git-machete-intellij-plugin by VirtusLab.

the class BranchLayoutTestSuite method withBranchSlideOut_givenDuplicatedBranchUnderItself_slidesOut.

@Test
public void withBranchSlideOut_givenDuplicatedBranchUnderItself_slidesOut() {
    // given
    String rootName = "root";
    String childName = "child";
    /*-
            root           slide out      root
              child         ----->
                child
    */
    val childBranchEntry = new BranchLayoutEntry(childName, /* customAnnotation */
    null, List.empty());
    List<IBranchLayoutEntry> childBranches = List.of(new BranchLayoutEntry(childName, /* customAnnotation */
    null, List.of(childBranchEntry)));
    val entry = new BranchLayoutEntry(rootName, /* customAnnotation */
    null, childBranches);
    val branchLayout = new BranchLayout(List.of(entry));
    // when
    IBranchLayout result = branchLayout.slideOut(childName);
    // then
    assertEquals(result.getRootEntries().size(), 1);
    assertEquals(result.getRootEntries().get(0).getName(), rootName);
    assertEquals(result.getRootEntries().get(0).getChildren().size(), 0);
}
Also used : lombok.val(lombok.val) BranchLayout(com.virtuslab.branchlayout.api.BranchLayout) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) Test(org.junit.Test)

Example 5 with IBranchLayoutEntry

use of com.virtuslab.branchlayout.api.IBranchLayoutEntry in project git-machete-intellij-plugin by VirtusLab.

the class SlideInBackgroundable method run.

@Override
@UIThreadUnsafe
public void run(ProgressIndicator indicator) {
    preSlideInRunnable.run();
    // `preSlideInRunnable` may perform some sneakily-asynchronous operations (e.g. checkoutRemoteBranch).
    // The high-level method used within the runnable do not allow us to schedule the tasks after them.
    // (Stepping deeper is not an option since we would lose some important logic or become very dependent on the internals of git4idea).
    // Hence we wait for the creation of the branch (with exponential backoff).
    waitForCreationOfLocalBranch();
    Path macheteFilePath = getMacheteFilePath(gitRepository);
    IBranchLayoutEntry childEntryByName = branchLayout.findEntryByName(slideInOptions.getName()).getOrNull();
    IBranchLayoutEntry entryToSlideIn;
    IBranchLayout targetBranchLayout;
    if (childEntryByName != null) {
        if (slideInOptions.shouldReattach()) {
            entryToSlideIn = childEntryByName;
            targetBranchLayout = branchLayout;
        } else {
            entryToSlideIn = childEntryByName.withChildren(List.empty());
            targetBranchLayout = branchLayout.slideOut(slideInOptions.getName());
        }
    } else {
        entryToSlideIn = new BranchLayoutEntry(slideInOptions.getName(), /* customAnnotation */
        null, /* children */
        List.empty());
        targetBranchLayout = branchLayout;
    }
    IBranchLayout newBranchLayout;
    try {
        newBranchLayout = targetBranchLayout.slideIn(parentName, entryToSlideIn);
    } catch (EntryDoesNotExistException e) {
        notifyError(format(getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.message.entry-does-not-exist"), parentName), e);
        return;
    } catch (EntryIsDescendantOfException e) {
        notifyError(format(getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.message.entry-is-descendant-of"), entryToSlideIn.getName(), parentName), e);
        return;
    }
    final IBranchLayout finalNewBranchLayout = newBranchLayout;
    Try.run(() -> branchLayoutWriter.write(macheteFilePath, finalNewBranchLayout, /* backupOldLayout */
    true)).onFailure(t -> IntelliJNotificationCompat.notifyError(project, /* title */
    getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.title.branch-layout-write-fail"), getMessageOrEmpty(t)));
}
Also used : GitVfsUtils.getMacheteFilePath(com.virtuslab.gitmachete.frontend.vfsutils.GitVfsUtils.getMacheteFilePath) Path(java.nio.file.Path) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) EntryDoesNotExistException(com.virtuslab.branchlayout.api.EntryDoesNotExistException) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) EntryIsDescendantOfException(com.virtuslab.branchlayout.api.EntryIsDescendantOfException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Aggregations

BranchLayoutEntry (com.virtuslab.branchlayout.api.BranchLayoutEntry)6 IBranchLayoutEntry (com.virtuslab.branchlayout.api.IBranchLayoutEntry)6 IBranchLayout (com.virtuslab.branchlayout.api.IBranchLayout)5 lombok.val (lombok.val)5 BranchLayout (com.virtuslab.branchlayout.api.BranchLayout)4 Test (org.junit.Test)4 EntryDoesNotExistException (com.virtuslab.branchlayout.api.EntryDoesNotExistException)1 EntryIsDescendantOfException (com.virtuslab.branchlayout.api.EntryIsDescendantOfException)1 GitVfsUtils.getMacheteFilePath (com.virtuslab.gitmachete.frontend.vfsutils.GitVfsUtils.getMacheteFilePath)1 UIThreadUnsafe (com.virtuslab.qual.guieffect.UIThreadUnsafe)1 Path (java.nio.file.Path)1