private TestRepository createTestRepository(TestProject project) throws IOException, Exception { TestRepository testRepository = new TestRepository(TestUtils.createGitDir(project)); testRepository.createMockSystemReader(ResourcesPlugin.getWorkspace().getRoot().getLocation()); testRepository.setUserAndEmail(GIT_USER, GIT_EMAIL); testRepository.connect(project.getProject()); testRepository.add(project.getFile(".project")); testRepository.initialCommit(); return testRepository; }
@After public void tearDown() throws Exception { testRepository.dispose(); testRepositoryClone.dispose(); testRepository2.dispose(); Activator.getDefault().getRepositoryCache().clear(); testProject.dispose(); testProject2.dispose(); }
@Test public void canCommitFileInProject() throws Exception { String fileName = "a.txt"; String fileContent = "*****@*****.**"; IFile file = testUtils.addFileToProject(testProject.getProject(), fileName, fileContent); testRepository.add(file); EGitUtils.commit(testProject.getProject(), null); testUtils.assertRepositoryContainsFilesWithContent( testRepository.getRepository(), new String[] {testUtils.getPathInRepository(file), fileContent}); }
@Test public void newUntrackedFileIsNotCountedIfIgnoreUntracked() throws Exception { assertFalse(EGitUtils.isDirty(testRepository.getRepository(), new NullProgressMonitor())); testRepository.createFile(testProject.getProject(), "a.txt", "42"); int numOfChanges = EGitUtils.countChanges(testRepository.getRepository(), false, new NullProgressMonitor()); assertEquals(0, numOfChanges); }
@Test public void originShouldBeDefaultRemoteRepo() throws Exception { // pre-conditions testRepository.addRemoteTo("git", "git://git.stuff/"); testRepository.addRemoteTo("foo", "https://foo.bar/"); testRepository.addRemoteTo("bar", "http://bar.foo/"); // Get 1st remote after remotes were ordered alphabetically // operation String defaultRepo = EGitUtils.getDefaultRemoteRepo(testProject.getProject()); // verification assertEquals("http://bar.foo/", defaultRepo); // Check origin is always default testRepository.addRemoteTo("origin", "http://origin/"); // operation defaultRepo = EGitUtils.getDefaultRemoteRepo(testProject.getProject()); // verification assertEquals("http://origin/", defaultRepo); }
@Test public void getRemoteHttpRepos() throws Exception { // pre-conditions testRepository.addRemoteTo("git", "git://git.stuff/"); testRepository.addRemoteTo("foo", "https://foo.bar/"); testRepository.addRemoteTo("bar", "http://bar.foo/"); testRepository.addRemoteTo("origin", "http://origin/"); // operation List<String> repos = EGitUtils.getRemoteGitRepos(testProject.getProject()); // verification assertEquals(3, repos.size()); assertEquals("http://origin/", repos.get(0)); assertEquals("http://bar.foo/", repos.get(1)); assertEquals("https://foo.bar/", repos.get(2)); }
@Test public void untrackedWhileIncludeUntrackedIsDirty() throws Exception { assertFalse(EGitUtils.isDirty(testRepository.getRepository(), new NullProgressMonitor())); testRepository.createFile(testProject.getProject(), "a.txt", "42"); assertTrue(EGitUtils.isDirty(testRepository.getRepository(), true, new NullProgressMonitor())); }
@Test public void canGetRepoForProject() throws Exception { Repository repository = EGitUtils.getRepository(testProject.getProject()); assertNotNull(repository); assertEquals(testRepository.getRepository(), repository); }