GitAdd { public GitAddResponse add(File repositoryPath, GitAddOptions options, List<File> paths) throws IOException, JavaGitException { CheckUtilities.checkFileValidity(repositoryPath.getAbsoluteFile()); IClient client = ClientManager.getInstance().getPreferredClient(); IGitAdd gitAdd = client.getGitAddInstance(); return gitAdd.add(repositoryPath, options, paths); }  GitAddResponse add(File repositoryPath, GitAddOptions options, List<File> paths); GitAddResponse addVerbose(File repositoryPath, List<File> paths); GitAddResponse addWithForce(File repositoryPath, List<File> paths); GitAddResponse addDryRun(File repositoryPath, List<File> paths); GitAddResponse add(File repositoryPath, GitAddOptions options, File file); GitAddResponse add(File repositoryPath, File file); GitAddResponse add(File repositoryPath, List<File> paths);  }
@Test public void testAddingFilesToRepository() throws IOException, JavaGitException { File file1 = FileUtilities.createFile(repoDirectory, "fileB.txt", "This is file fileB.txt"); File tmpDir = new File(repoDirectory.getAbsolutePath() + File.separator + "dirA"); if (tmpDir.mkdir()) { File file2 = FileUtilities.createFile(repoDirectory, "dirA/fileB.txt", "Sample Contents"); List<File> paths = new ArrayList<File>(); paths.add(file1); paths.add(new File("dirA")); paths.add(file2); GitAddOptions options = new GitAddOptions(); options.setVerbose(true); GitAddResponse response = gitAdd.add(repoDirectory, options, paths); assertEquals("Number of files added is incorrect", 2, response.getFileListSize()); } else { throw new IOException("Unable to create directory: " + tmpDir); } }
@Test public void testAddingOneFileToRepository() throws IOException, JavaGitException { File file1 = FileUtilities.createFile(repoDirectory, "fileA.txt", "This is file fileA.txt"); File tmpDir = new File(repoDirectory.getPath() + File.separator + "dirA"); if (tmpDir.mkdir()) { File file2 = FileUtilities.createFile(repoDirectory, "dirA" + File.separator + "fileB.txt", "Sample Contents fileB.txt"); gitAdd.add(repoDirectory, file1); gitAdd.add(repoDirectory, new File("dirA")); gitAdd.add(repoDirectory, file2); GitStatusResponse statusResponse = gitStatus.status(repoDirectory); assertEquals("File to commit", 2, statusResponse.getNewFilesToCommitSize()); } else { fail("Failed to add files to repository"); throw new IOException("Unable to create directory: " + tmpDir); } }
@Test public void testAddingFilesToRepositoryWithNoOptions() throws IOException, JavaGitException { File file1 = FileUtilities.createFile(repoDirectory, "fileA.txt", "This is file fileA.txt"); File tmpDir = new File(repoDirectory.getAbsolutePath() + File.separator + "dirA"); if (tmpDir.mkdir()) { File file2 = FileUtilities.createFile(repoDirectory, "dirA" + File.separator + "fileB.txt", "Sample Contents fileB.txt"); List<File> paths = new ArrayList<File>(); paths.add(file1); paths.add(new File("dirA")); paths.add(file2); gitAdd.add(repoDirectory, paths); GitStatusResponse statusResponse = gitStatus.status(repoDirectory); assertEquals("File to commit", 2, statusResponse.getNewFilesToCommitSize()); } else { fail("Failed to add files to repository"); throw new IOException("Unable to create directory: " + tmpDir); } }