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();
/** * Checks out a file into the working directory. * * @param path - The file path. * @throws GitAPIException - failed. */ public void checkoutFile(final String path) throws GitAPIException { git.checkout() .addPath(path) .call(); }
private boolean checkoutFromRemoteHead(RepositoryContext gitRepoCtx, List<String> paths) { boolean checkoutSuccess = false; CheckoutCommand checkoutCmd = gitRepoCtx.getGit().checkout(); for (String path : paths) { checkoutCmd.addPath(path); if (log.isDebugEnabled()) { log.debug("Added the file path " + path + " to checkout from the remote repository"); } } // specify the start point as the HEAD of remote repository checkoutCmd.setStartPoint(GitDeploymentSynchronizerConstants.REMOTES_ORIGIN_MASTER); try { checkoutCmd.call(); checkoutSuccess = true; log.info("Checked out the conflicting files from the remote repository successfully"); } catch (GitAPIException e) { log.error("Checking out artifacts from index failed", e); } return checkoutSuccess; }
private void resolveConflict(final String path) { try { git.reset().addPath(path).call(); git.checkout().addPath(path).call(); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } }
/** * Checks out a single file from a commit in the repository and adds it to the working dir. * * @param path - Full path to the file. * @param ref - String representing a commit in the repository. * @throws GitAPIException - failed. */ public void checkout(final String path, final String ref) throws GitAPIException { git.checkout() .setStartPoint(ref) .addPath(path) .call(); }
public boolean revertChanges(Log log, List<File> changedFiles) throws MojoExecutionException { if (hasReverted) { return true; } boolean hasErrors = false; File workTree = workingDir(); for (File changedFile : changedFiles) { try { String pathRelativeToWorkingTree = Repository.stripWorkDir(workTree, changedFile); git.checkout().addPath(pathRelativeToWorkingTree).call(); } catch (Exception e) { hasErrors = true; log.error("Unable to revert changes to " + changedFile + " - you may need to manually revert this file. Error was: " + e.getMessage()); } } hasReverted = true; return !hasErrors; }
private boolean checkout() { try { mRepo.getGit().checkout().addPath(mPath).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; }
private boolean checkout() { try { mRepo.getGit().checkout().addPath(mPath).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; }
private void resetLocalRepoToProperState(Git git) throws GitAPIException { log.warn("conflicts in local repo - trying to fix them one by one..."); Status status = git.status().call(); log.info("cleaning up directory.."); Set<String> removedFiles = gitWrapper.cleanDirectories(git); for (String removedFile : removedFiles) { log.info("\t removed {}", removedFile); } ResetCommand reset = gitWrapper.resetRepo(git); reset.setRef(Constants.HEAD); log.info("trying to remove conflicted files from workspace.."); for (String conflictedFile : status.getConflicting()) { log.info("\t resetting {}", conflictedFile); reset.addPath(conflictedFile); } log.info("trying to remove uncommitted files from workspace.."); for (String addedFile : status.getAdded()) { log.info("\t resetting {}", addedFile); reset.addPath(addedFile); } reset.call(); log.info("reverting modified files to latest known state.."); CheckoutCommand checkout = gitWrapper.checkOut(git); for (String modifiedFile : status.getModified()) { log.info("\t reverting {}", modifiedFile); checkout.addPath(modifiedFile); } checkout.call(); }
private void replaceWith(String[] files, boolean headRevision) { if (files == null || files.length == 0) return; CheckoutCommand checkoutCommand = new Git(currentRepository).checkout(); if (headRevision) checkoutCommand.setStartPoint(Constants.HEAD); for (String path : files) checkoutCommand.addPath(path); try { checkoutCommand.call(); } catch (Exception e) { Activator.handleError(UIText.StagingView_checkoutFailed, e, true); } }
/** * Fetch the version of a config after a particular commit in its history * * @param jobId The job id to check * @param commitId The commit id to fetch * @return The contents of the file after the specified time * @throws GitAPIException If there is a problem retrieving the file after the specified commit * @throws IOException If there is a problem writing to the file */ public String fetchJobConfigFromHistory(String jobId, String commitId) throws GitAPIException, IOException { synchronized (gitDir) { File file = getFileForJobId(jobId); git.checkout().addPath(getPathForJobId(jobId)).setStartPoint(commitId).setName("master").call(); String rv = new String(LessFiles.read(file)); git.reset().setMode(ResetCommand.ResetType.HARD).call(); return rv; } }
command.setStartPoint(name); for (String path : paths) command.addPath(path); } else { command.setCreateBranch(createBranch);
.call(); for (String p : status.getModified()) { gitPatchRepository.checkout(fork).addPath(p).call();
.call(); for (String p : status.getModified()) { gitPatchRepository.checkout(fork).addPath(p).call();