1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*******************************************************************************
* Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.core.test.op;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.op.TrackOperation;
import org.eclipse.egit.core.op.UntrackOperation;
import org.eclipse.egit.core.test.DualRepositoryTestCase;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.lib.Constants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TrackUntrackOperationTest extends DualRepositoryTestCase {
File workdir;
IProject project;
String projectName = "TrackTest";
@Before
public void setUp() throws Exception {
workdir = testUtils.getTempDir("Repository1");
repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
// now we create a project in repo1
project = testUtils
.createProjectInLocalFileSystem(workdir, projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
}
@After
public void tearDown() throws Exception {
project.close(null);
project.delete(false, false, null);
repository1.dispose();
repository1 = null;
testUtils.deleteRecursive(workdir);
}
@Test
public void testTrackFiles() throws Exception {
final ArrayList<IFile> files = new ArrayList<IFile>();
DirCache cache = DirCache.read(repository1.getRepository());
assertEquals("Wrong cache entry count", 0, cache.getEntryCount());
project.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile)
files.add((IFile) resource);
return true;
}
});
IFile[] fileArr = files.toArray(new IFile[files.size()]);
TrackOperation trop = new TrackOperation(fileArr);
trop.execute(new NullProgressMonitor());
cache.read();
assertEquals("Wrong cache entry count", 2, cache.getEntryCount());
UntrackOperation utop = new UntrackOperation(Arrays.asList(fileArr));
utop.execute(new NullProgressMonitor());
cache.read();
assertEquals("Wrong cache entry count", 0, cache.getEntryCount());
}
@Test
public void testTrackProject() throws Exception {
final ArrayList<IContainer> containers = new ArrayList<IContainer>();
containers.add(project);
DirCache cache = DirCache.read(repository1.getRepository());
assertEquals("Wrong cache entry count", 0, cache.getEntryCount());
IContainer[] fileArr = containers.toArray(new IContainer[containers
.size()]);
TrackOperation trop = new TrackOperation(fileArr);
trop.execute(new NullProgressMonitor());
cache.read();
assertEquals("Wrong cache entry count", 2, cache.getEntryCount());
}
}
|