本文整理汇总了Java中org.eclipse.jgit.api.ResetCommand.setMode方法的典型用法代码示例。如果您正苦于以下问题:Java ResetCommand.setMode方法的具体用法?Java ResetCommand.setMode怎么用?Java ResetCommand.setMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.ResetCommand
的用法示例。
在下文中一共展示了ResetCommand.setMode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pullRepository
import org.eclipse.jgit.api.ResetCommand; //导入方法依赖的package包/类
public static void pullRepository() {
try {
logger.info("Scanning devices folder for changes.");
git.add().addFilepattern(".").call();
Status status = git.status().call();
if (status.getChanged().size()>0 || status.getAdded().size()>0 || status.getModified().size()>0) {
logger.info("Changes have been found. Doing a hard reset (removing user modifications).");
ResetCommand reset = git.reset();
reset.setMode(ResetType.HARD);
reset.setRef(Constants.HEAD);
reset.call();
}
logger.info("Pulling changes from github.");
git.pull().call();
} catch (NoHeadException e) {
logger.info("Pull failed. Trying to clone repository instead");
closeRepository();
cloneRepository();
}
catch (Exception e1) {
closeRepository();
}
}
示例2: resetHard
import org.eclipse.jgit.api.ResetCommand; //导入方法依赖的package包/类
private Ref resetHard(Git git, String label, String ref) {
ResetCommand reset = git.reset();
reset.setRef(ref);
reset.setMode(ResetType.HARD);
try {
Ref resetRef = reset.call();
if (resetRef != null) {
this.logger.info(
"Reset label " + label + " to version " + resetRef.getObjectId());
}
return resetRef;
}
catch (Exception ex) {
String message = "Could not reset to remote for " + label + " (current ref="
+ ref + "), remote: " + git.getRepository().getConfig()
.getString("remote", "origin", "url");
warn(message, ex);
return null;
}
}
示例3: reset
import org.eclipse.jgit.api.ResetCommand; //导入方法依赖的package包/类
@Override
public void reset(ResetParams params) throws GitException {
try {
ResetCommand resetCommand = getGit().reset();
resetCommand.setRef(params.getCommit());
List<String> patterns = params.getFilePattern();
patterns.forEach(resetCommand::addPath);
if (params.getType() != null && patterns.isEmpty()) {
switch (params.getType()) {
case HARD:
resetCommand.setMode(ResetType.HARD);
break;
case KEEP:
resetCommand.setMode(ResetType.KEEP);
break;
case MERGE:
resetCommand.setMode(ResetType.MERGE);
break;
case MIXED:
resetCommand.setMode(ResetType.MIXED);
break;
case SOFT:
resetCommand.setMode(ResetType.SOFT);
break;
}
}
resetCommand.call();
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
示例4: reset
import org.eclipse.jgit.api.ResetCommand; //导入方法依赖的package包/类
public void reset(String refToResetTo) {
ResetCommand command = _git.reset();
command.setRef(refToResetTo);
command.setMode(ResetType.HARD);
try {
command.call();
} catch (Throwable e) {
throw new RuntimeException(String.format("Failed to reset to [%s]", refToResetTo), e);
}
}
示例5: testGitInit
import org.eclipse.jgit.api.ResetCommand; //导入方法依赖的package包/类
@Test
public void testGitInit() throws IOException, GitAPIException {
String targetPath = getClass().getProtectionDomain().getCodeSource().getLocation().getFile() + "/..";
System.setProperty(PLUMBER_GIT_URL.configKey(), "[email protected]:github/testrepo.git");
System.setProperty(PLUMBER_GIT_PATH.configKey(), targetPath + "/junit-git-iaac");
PlumberConfig.reload();
System.clearProperty(PLUMBER_GIT_URL.configKey());
System.clearProperty(PLUMBER_GIT_PATH.configKey());
File gitFolder = new File(PlumberConfig.get(PLUMBER_GIT_PATH));
if (gitFolder.exists() && gitFolder.isDirectory()) {
FileUtils.deleteDirectory(gitFolder);
}
assertTrue(gitFolder.mkdirs());
GitWorker gitWorker = new GitWorker(PlumberConfig.get(PLUMBER_GIT_URL), PlumberConfig.get(PLUMBER_GIT_PATH));
gitWorker.init();
gitWorker = new GitWorker(PlumberConfig.get(PLUMBER_GIT_URL), PlumberConfig.get(PLUMBER_GIT_PATH));
gitWorker.init();
Git git = gitWorker.getGit();
assertNotNull(git);
Iterator<RevCommit> log = git.log().call().iterator();
assertTrue(log.hasNext());
String latestRef = log.next().getName();
assertTrue(log.hasNext());
String previousRef = log.next().getName();
assertNotEquals(latestRef, previousRef);
ResetCommand resetCommand = git.reset();
resetCommand.setMode(ResetCommand.ResetType.HARD);
resetCommand.setRef("HEAD~1");
resetCommand.call();
assertTrue(git.log().call().iterator().hasNext());
log = git.log().call().iterator();
assertTrue(log.hasNext());
String latestRefAfterRebase = log.next().getName();
assertEquals(previousRef, latestRefAfterRebase);
PullResult pullResult = gitWorker.pull();
assertTrue(pullResult.isSuccessful());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, pullResult.getMergeResult().getMergeStatus());
log = git.log().call().iterator();
assertTrue(log.hasNext());
String latestRefAfterRePull = log.next().getName();
assertEquals(latestRef, latestRefAfterRePull);
if (gitFolder.exists() && gitFolder.isDirectory()) {
FileUtils.deleteDirectory(gitFolder);
}
}