public IStatus commit(String commitMessage) { IStatus status = doCommit(commitMessage); if (status.isOK()) { repository.hasChanged(); } // even if a commit fails, the repository's changed files listing may have changed. refresh(new NullProgressMonitor()); return status; }
public void testSwitchBranchClosesOpenProjectsThatDontExistOnDestinationBranch() throws Throwable { testAddBranch(); assertCurrentBranch("master"); assertSwitchBranch("my_new_branch"); GitIndex index = getRepo().index(); assertTrue("Expected changed file listing to be empty", index.changedFiles().isEmpty()); // Create a new project on this branch! String projectName = "project_on_branch" + System.currentTimeMillis(); File projectDir = getRepo().workingDirectory().append(projectName).toFile(); projectDir.mkdirs(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(getRepo().workingDirectory().append(projectName)); project.create(description, new NullProgressMonitor()); // Commit the project on this branch! index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changed = index.changedFiles(); assertEquals( "repository changed file listing should contain one entry for new .project file, but does not", 1, changed.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changed.get(0)); // Stage the new file assertStageFiles(index, changed); assertNewStagedFile(changed.get(0)); assertCommit(index, "Initial commit"); assertSwitchBranch("master"); // Assert that the new project is closed! project = workspace.getRoot().getProject(projectName); assertFalse(project.isOpen()); // assert that there's no .project file stranded there File dotProject = new File(projectDir, IProjectDescription.DESCRIPTION_FILE_NAME); assertFalse(dotProject.exists()); }
public void testRefresh() throws Exception { GitRepository repo = getRepo(); // Write 1000 small files to the repo writeFiles(repo.workingDirectory(), 1000); GitIndex index = repo.index(); for (int i = 0; i < 1200; i++) { startMeasuring(); index.refresh(null); stopMeasuring(); } commitMeasurements(); assertPerformance(); }
public void testDeleteUnMergedBranch() throws Throwable { testAddBranch(); assertSwitchBranch("my_new_branch"); // Now we need to make changes, commit and then switch back to master GitIndex index = getRepo().index(); // TODO Refactor out common code with testAddFileStageUnstageCommit // Actually add a file to the location String txtFile = getRepo().workingDirectory() + File.separator + "file_on_branch.txt"; FileWriter writer = new FileWriter(txtFile); writer.write("Hello Branched World!"); writer.close(); // refresh the index index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changedFiles = index.changedFiles(); assertEquals( "repository changed file listing should contain one entry for a new file_on_branch.txt file, but does not", 1, changedFiles.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changedFiles.get(0)); // Stage the new file assertStageFiles(index, changedFiles); assertNewStagedFile(changedFiles.get(0)); assertCommit(index, "Initial commit"); // Now switch to master assertSwitchBranch("master"); IStatus status = getRepo().deleteBranch("my_new_branch"); assertFalse( "Deleting an umerged branch didn't return an error status (as it should)", status.isOK()); assertEquals(1, status.getCode()); // Can't rely on the unmerged failure message from git to remain the same across versions. // assertEquals( // "error: The branch 'my_new_branch' is not an ancestor of your current HEAD.\nIf you are sure // you want to delete it, run 'git branch -D my_new_branch'.", // status.getMessage()); }
public void testCommitMessageWithDoubleQuotes() throws Throwable { GitRepository repo = createRepo(); GitIndex index = repo.index(); assertTrue(index.changedFiles().isEmpty()); // Actually add a file to the location FileWriter writer = new FileWriter(fileToAdd()); writer.write("Hello World!"); writer.close(); // refresh the index index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changed = index.changedFiles(); assertEquals( "Repository changed file listing should contain one entry for the new file, but does not", 1, changed.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changed.get(0)); // stage assertStageFiles(index, changed); assertNewStagedFile(changed.get(0)); // commit final String commitMessage = "Initial commit with \"double quotes\" inside the message!"; assertCommit(index, commitMessage); // now grab the resulting log to see if the message escaped the quotes too many times! File file = repo.gitFile(GitRepository.COMMIT_EDITMSG); FileInputStream stream = null; try { stream = new FileInputStream(file); String result = IOUtil.read(stream); assertEquals(commitMessage + "\n", result); } finally { if (stream != null) { stream.close(); } } }