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
|
/*******************************************************************************
* Copyright (C) 2014, Christian Halstrick <christian.halstrick@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;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.Activator;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class SubmoduleAndContainerTreeIteratorTest {
private TestUtils testUtils;
private IProject childProject;
private File childProjectDir;
private TestRepository childRepository;
private IProject parentProject;
private File parentProjectDir;
private TestRepository parentRepository;
private IFile parentFile;
private FileTreeIterator treeIt;
@Before
public void setUp() throws Exception {
testUtils = new TestUtils();
// Create child repo and project
childProject = testUtils.createProjectInLocalFileSystem("child");
childProjectDir = childProject.getRawLocation().toFile();
childRepository = new TestRepository(new File(childProjectDir,
Constants.DOT_GIT));
testUtils.addFileToProject(childProject, "child.txt", "Hello world");
childRepository.connect(childProject);
// We have to wait after until the filesystem timer has advanced to
// avoid smudged states
RepositoryTestCase.fsTick(null);
childRepository.trackAllFiles(childProject);
childRepository.commit("Initial commit");
// Create parent repo and project
parentProject = testUtils.createProjectInLocalFileSystem("parent");
parentProjectDir = parentProject.getRawLocation().toFile();
parentRepository = new TestRepository(new File(parentProjectDir,
Constants.DOT_GIT));
parentFile = testUtils.addFileToProject(parentProject, "parent.txt",
"Hello world");
Git.wrap(parentRepository.getRepository()).submoduleAdd()
.setPath("children/child")
.setURI(childProjectDir.toURI().toString()).call();
parentRepository.connect(parentProject);
RepositoryTestCase.fsTick(null);
parentRepository.trackAllFiles(parentProject);
parentRepository.commit("Initial commit");
treeIt = new FileTreeIterator(parentRepository.getRepository());
}
@After
public void tearDown() throws Exception {
childRepository.dispose();
parentRepository.dispose();
childProject.delete(true, true, null);
parentProject.delete(true, true, null);
Activator.getDefault().getRepositoryCache().clear();
testUtils.deleteTempDirs();
}
@Test
public void testCleanStateAfterInit() throws NoWorkTreeException,
GitAPIException {
Git parentGit = Git.wrap(parentRepository.getRepository());
Status status = parentGit.status().setWorkingTreeIt(treeIt).call();
assertTrue(status.isClean());
}
@Test
public void testCleanStateFirstCommit() throws NoWorkTreeException,
GitAPIException, IOException, CoreException, InterruptedException {
testUtils.changeContentOfFile(parentProject, parentFile, "new content");
RepositoryTestCase.fsTick(null);
parentRepository.trackAllFiles(parentProject);
parentRepository.commit("modified parent.txt");
Git parentGit = Git.wrap(parentRepository.getRepository());
Status status = parentGit.status().setWorkingTreeIt(treeIt).call();
assertTrue(status.isClean());
}
}
|