GitCheckout { public GitCheckoutResponse checkout(File repositoryPath, GitCheckoutOptions options, Ref branch) throws IOException, JavaGitException { CheckUtilities.checkFileValidity(repositoryPath); CheckUtilities.validateArgumentRefType(branch, RefType.BRANCH, "Branch name"); IClient client = ClientManager.getInstance().getPreferredClient(); IGitCheckout gitCheckout = client.getGitCheckoutInstance(); return gitCheckout.checkout(repositoryPath, options, branch); }  GitCheckoutResponse checkout(File repositoryPath, GitCheckoutOptions options, Ref branch); GitCheckoutResponse checkout(File repositoryPath, List<File> paths); GitCheckoutResponse checkout(File repositoryPath, GitCheckoutOptions options, Ref branch,
      File file); GitCheckoutResponse checkout(File repositoryPath, GitCheckoutOptions options, Ref branch,
      List<File> paths); GitCheckoutResponse checkout(File repositoryPath, Ref ref, List<File> paths);  }
@Test public void testCreatingNewBranchFromMaster() throws IOException, JavaGitException { GitCheckoutOptions options = new GitCheckoutOptions(); options.setOptB(Ref.createBranchRef("testBranch")); Ref branch = Ref.createBranchRef("master"); GitCheckoutResponse response = gitCheckout.checkout(repositoryDirectory, options, branch); assertEquals("New Branch created should be created with name- testBranch", "\"testBranch\"", response.getNewBranch().getName()); }
@Test public void testCheckingOutLocalllyDeletedFiles() throws JavaGitException, IOException { List<File> filePaths = new ArrayList<File>(); File tmpFile; try { filePaths.add( tmpFile = new File(repositoryPath + File.separator + "foobar01")); if (!tmpFile.exists()) { System.out.println("tmpFile does not exit: " + tmpFile.getPath()); } if (tmpFile.delete()) { GitCheckoutResponse response = gitCheckout.checkout(repositoryDirectory, filePaths); File checkedOutFile = new File(repositoryPath + File.separator + "foobar01"); assertTrue(checkedOutFile.exists()); FileUtilities.modifyFileContents(file2, "Test for append to a file"); GitCheckoutOptions options = new GitCheckoutOptions(); Ref branch = Ref.createBranchRef("master"); response = gitCheckout.checkout(repositoryDirectory, options, branch); assertEquals("Modified File exists", 1, response.getNumberOfModifiedFiles()); } else { fail("File delete failed"); } } catch (IOException e ) { System.err.println(e.getMessage()); e.printStackTrace(); } }
@Test public void testCheckingOutFileFromAnotherBranch() throws JavaGitException, IOException { GitCheckoutOptions options = new GitCheckoutOptions(); Ref branch1 = Ref.createBranchRef("testBranch01"); options.setOptB(branch1); Ref branch = Ref.createBranchRef("master"); gitCheckout.checkout(repositoryDirectory, options, branch); File file3 = new File( repositoryDirectory.getPath() + File.separator + "foobar03"); file3.createNewFile(); gitAdd.add(repositoryDirectory, null, new File("foobar03")); gitCommit.commit(repositoryDirectory, "Added foobar03 to the repository"); assertFileExistsInDirectory(repositoryDirectory, new File("foobar03")); Ref master = Ref.createBranchRef("master"); options = new GitCheckoutOptions(); Ref newBranch = Ref.createBranchRef("testBranch02"); options.setOptB(newBranch); gitCheckout.checkout(repositoryDirectory, options, master); assertFalse(file3.exists()); gitCheckout.checkout(repositoryDirectory, null, branch1, file3); assertFileExistsInDirectory(repositoryDirectory, new File("foobar03")); }