Capture current selection before opening dialogs in replace actions
[egit/eclipse.git] / org.eclipse.egit.core.test / src / org / eclipse / egit / core / internal / merge / TreeWalkResourceVariantTreeProviderTest.java
blobd1508c728ab6f0e486bb22a4a87844915219641f
1 /*******************************************************************************
2 * Copyright (C) 2015 Obeo and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org.eclipse.egit.core.internal.merge;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
14 import java.io.File;
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.jgit.revwalk.RevCommit;
20 import org.eclipse.jgit.revwalk.RevTree;
21 import org.eclipse.jgit.revwalk.RevWalk;
22 import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
23 import org.eclipse.jgit.treewalk.TreeWalk;
24 import org.eclipse.team.core.variants.IResourceVariant;
25 import org.junit.Test;
27 public class TreeWalkResourceVariantTreeProviderTest extends VariantsTestCase {
28 @Test
29 public void testTreeWalkTrees() throws Exception {
30 File file1 = testRepo.createFile(iProject, "file1");
31 File file2 = testRepo.createFile(iProject, "file2");
33 testRepo.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_1,
34 "first file - initial commit");
35 RevCommit baseCommit = testRepo.appendContentAndCommit(iProject, file2,
36 INITIAL_CONTENT_2, "second file - initial commit");
38 IFile iFile1 = testRepo.getIFile(iProject, file1);
39 IFile iFile2 = testRepo.getIFile(iProject, file2);
41 testRepo.createAndCheckoutBranch(MASTER, BRANCH);
43 final String branchChanges = "branch changes\n";
44 setContentsAndCommit(testRepo, iFile2, branchChanges
45 + INITIAL_CONTENT_2, "branch commit");
47 testRepo.checkoutBranch(MASTER);
49 final String masterChanges = "\nsome changes";
50 setContentsAndCommit(testRepo, iFile1, INITIAL_CONTENT_1
51 + masterChanges, "master commit");
52 iProject.refreshLocal(IResource.DEPTH_INFINITE,
53 new NullProgressMonitor());
54 // end setup
56 // as if we tried to merge branch into master
57 try (RevWalk walk = new RevWalk(repo)) {
58 RevTree baseTree = walk.parseTree(baseCommit.getId());
59 RevTree sourceTree = walk.parseTree(repo.resolve(MASTER));
60 RevTree remoteTree = walk.parseTree(repo.resolve(BRANCH));
61 TreeWalk treeWalk = new NameConflictTreeWalk(repo);
62 treeWalk.addTree(baseTree);
63 treeWalk.addTree(sourceTree);
64 treeWalk.addTree(remoteTree);
65 TreeWalkResourceVariantTreeProvider treeProvider = new TreeWalkResourceVariantTreeProvider(
66 repo, treeWalk, 0, 1, 2);
68 assertEquals(1, treeProvider.getRoots().size());
69 assertTrue(treeProvider.getRoots().contains(iProject));
71 assertTrue(treeProvider.getKnownResources().contains(iFile1));
72 assertTrue(treeProvider.getKnownResources().contains(iFile2));
74 IResourceVariant file1BaseVariant = treeProvider.getBaseTree()
75 .getResourceVariant(iFile1);
76 IResourceVariant file2BaseVariant = treeProvider.getBaseTree()
77 .getResourceVariant(iFile2);
78 assertContentEquals(file1BaseVariant, INITIAL_CONTENT_1);
79 assertContentEquals(file2BaseVariant, INITIAL_CONTENT_2);
81 IResourceVariant file1TheirsVariant = treeProvider.getRemoteTree()
82 .getResourceVariant(iFile1);
83 IResourceVariant file2TheirsVariant = treeProvider.getRemoteTree()
84 .getResourceVariant(iFile2);
85 assertContentEquals(file1TheirsVariant, INITIAL_CONTENT_1);
86 assertContentEquals(file2TheirsVariant, branchChanges
87 + INITIAL_CONTENT_2);
89 IResourceVariant file1OursVariant = treeProvider.getSourceTree()
90 .getResourceVariant(iFile1);
91 IResourceVariant file2OursVariant = treeProvider.getSourceTree()
92 .getResourceVariant(iFile2);
93 assertContentEquals(file1OursVariant, INITIAL_CONTENT_1
94 + masterChanges);
95 assertContentEquals(file2OursVariant, INITIAL_CONTENT_2);