@Signature public Memory reset(Environment env, ArrayMemory settings) throws GitAPIException { ResetCommand reset = getWrappedObject().reset(); Memory mode = settings.valueOfIndex("mode"); if (mode.isNotNull()) { reset.setMode(ResetCommand.ResetType.valueOf(mode.toString())); } Memory ref = settings.valueOfIndex("ref"); if (ref.isNotNull()) { reset.setRef(ref.toString()); } reset.disableRefLog(settings.valueOfIndex("disableRefLog").toBoolean()); Memory paths = settings.valueOfIndex("paths"); if (paths.isNotNull()) { ForeachIterator iterator = paths.getNewIterator(env); if (iterator != null) { while (iterator.next()) { reset.addPath(iterator.getValue().toString()); } } else { reset.addPath(paths.toString()); } } Ref call = reset.call(); return GitUtils.valueOf(call); }
ResetCommand reset = new Git(repository).reset(); reset.setRef(Constants.HEAD); reset.addPath("foo.txt"); reset.call();
/** * Reset. * * @param path the path * @throws GitAPIException the exception */ public void reset(final String path) throws GitAPIException { if (!isUndefined()) { git.reset().addPath(path).call(); } }
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); } }
private void resetToRemoteHead(RepositoryContext gitRepoCtx, List<String> paths) { ResetCommand resetCmd = gitRepoCtx.getGit().reset(); // reset type is HARD, to remote master branch resetCmd.setMode(ResetCommand.ResetType.HARD). setRef(GitDeploymentSynchronizerConstants.ORIGIN + "/" + GitDeploymentSynchronizerConstants.MASTER); // add paths for (String path : paths) { resetCmd.addPath(path); if (log.isDebugEnabled()) { log.debug("Added the file path " + path + " to reset"); } } try { resetCmd.call(); log.info("Reset the local branch to origin master successfully"); } catch (GitAPIException e) { log.error("Reset to origin master failed", e); } }
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(); }