private void checkout(String branchName) throws GitAPIException { try { git.checkout().setName(branchName).call(); } catch (GitAPIException e) { LOGGER.error("[CONFIG_MERGE] Checkout to branch {} failed", branchName, e); throw e; } }
private Ref checkout(Git git, String label) throws GitAPIException { CheckoutCommand checkout = git.checkout(); if (shouldTrack(git, label)) { trackBranch(git, checkout, label); } else { // works for tags and local branches checkout.setName(label); } return checkout.call(); }
@Test public void shouldSwitchToMasterAndDeleteTempBranches() throws Exception, GitAPIException { configRepo.checkin(goConfigRevision("v1", "md5-1")); configRepo.createBranch(ConfigRepository.BRANCH_AT_HEAD, configRepo.getCurrentRevCommit()); configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit()); configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call(); assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION)); assertThat(configRepo.git().branchList().call().size(), is(3)); configRepo.cleanAndResetToMaster(); assertThat(configRepo.git().getRepository().getBranch(), is("master")); assertThat(configRepo.git().branchList().call().size(), is(1)); }
@Test public void shouldCleanAndResetToMasterDuringInitialization() throws Exception { configRepo.checkin(goConfigRevision("v1", "md5-1")); configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit()); configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call(); assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION)); new ConfigRepository(systemEnvironment).initialize(); assertThat(configRepo.git().getRepository().getBranch(), is("master")); assertThat(configRepo.git().branchList().call().size(), is(1)); }
public static Path checkout(Path path, String branch) throws GitException { try (Git git = Git.open(path.toFile())) { git .checkout() .setName(branch) .call(); } catch (Throwable throwable) { throw new GitException("fetch tags error", throwable); } return path; }
public static void main(String[] args) throws IOException, GitAPIException { try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) { try (final Git git = new Git(repo)) { final String testFile = "README.md"; // Modify the file FileUtils.write(new File(testFile), new Date().toString(), "UTF-8"); System.out.println("Modified files: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, true).call(); System.out.println("Modified files after assume-changed: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, false).call(); System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git)); git.checkout().addPath(testFile).call(); System.out.println("Modified files after reset: " + getModifiedFiles(git)); } } }
public static void main(String[] args) throws IOException, GitAPIException { try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) { try (final Git git = new Git(repo)) { final String testFile = "README.md"; // Modify the file FileUtils.write(new File(testFile), new Date().toString(), "UTF-8"); System.out.println("Modified files: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, true).call(); System.out.println("Modified files after assume-changed: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, false).call(); System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git)); git.checkout().addPath(testFile).call(); System.out.println("Modified files after reset: " + getModifiedFiles(git)); } } }
git.checkout().addPath(fileName).call();
git.checkout().addPath(fileName).call();
return GitUtils.valueOf(command.call());
private void addSubmodule(String name, String url, String path, String revision, List<CopyFile> copyfiles, List<LinkFile> linkfiles, Git git) throws GitAPIException, IOException { assert (!repo.isBare()); assert (git != null); if (!linkfiles.isEmpty()) { throw new UnsupportedOperationException( JGitText.get().nonBareLinkFilesNotSupported); } SubmoduleAddCommand add = git.submoduleAdd().setName(name).setPath(path) .setURI(url); if (monitor != null) add.setProgressMonitor(monitor); Repository subRepo = add.call(); if (revision != null) { try (Git sub = new Git(subRepo)) { sub.checkout().setName(findRef(revision, subRepo)).call(); } subRepo.close(); git.add().addFilepattern(path).call(); } for (CopyFile copyfile : copyfiles) { copyfile.copy(); git.add().addFilepattern(copyfile.dest).call(); } }
try { co.setProgressMonitor(monitor); co.setName(newCommit.name()).call(); if (headName.startsWith(Constants.R_HEADS)) { RefUpdate rup = repo.updateRef(headName);
/** * Checks out the passed ref to be the current branch of the repository. * * @param ref - String representing a commit in the repository. * @throws GitAPIException - failed. */ public void checkout(final String ref) throws GitAPIException { git.checkout() .setName(ref) .call(); }
public void checkout(Repository repository, String commitId) throws Exception { logger.info("Checking out {} {} ...", repository.getDirectory().getParent().toString(), commitId); try (Git git = new Git(repository)) { CheckoutCommand checkout = git.checkout().setName(commitId); checkout.call(); } // File workingDir = repository.getDirectory().getParentFile(); // ExternalProcess.execute(workingDir, "git", "checkout", commitId); }
public void checkoutFromLocal(String name, String branch) throws GitAPIException, JGitInternalException, StopTaskException { mRepo.getGit().checkout().setCreateBranch(true).setName(branch) .setStartPoint(name).call(); }
public void checkoutFromLocal(String name, String branch) throws GitAPIException, JGitInternalException, StopTaskException { mRepo.getGit().checkout().setCreateBranch(true).setName(branch) .setStartPoint(name).call(); }
public void checkoutFromRemote(String remoteBranchName, String branchName) throws GitAPIException, JGitInternalException, StopTaskException { mRepo.getGit().checkout().setCreateBranch(true).setName(branchName) .setStartPoint(remoteBranchName).call(); mRepo.getGit() .branchCreate() .setUpstreamMode( CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint(remoteBranchName).setName(branchName) .setForce(true).call(); } }