org.eclipse.jgit.lib.RepositoryState Java Examples
The following examples show how to use
org.eclipse.jgit.lib.RepositoryState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetCloneAndPull() throws Exception { // see bug 339254 createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); String contentLocation = clone(workspaceId, project).getString(ProtocolConstants.KEY_CONTENT_LOCATION); JSONArray clonesArray = listClones(workspaceId, null); assertEquals(1, clonesArray.length()); Repository r = getRepositoryForContentLocation(contentLocation); // overwrite user settings, do not rebase when pulling, see bug 372489 StoredConfig cfg = r.getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false); cfg.save(); // TODO: replace with RESTful API when ready, see bug 339114 Git git = Git.wrap(r); PullResult pullResult = git.pull().call(); assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE); assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState()); }
Example #2
Source File: UIGit.java From hop with Apache License 2.0 | 5 votes |
@Override public boolean hasStagedFiles() { if ( git.getRepository().getRepositoryState() == RepositoryState.SAFE ) { return !getStagedFiles().isEmpty(); } else { return git.getRepository().getRepositoryState().canCommit(); } }
Example #3
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void run () throws GitException { Repository repository = getRepository(); ObjectId originalCommit = getOriginalCommit(); ObjectId head = getHead(); List<RebaseTodoLine> steps; try { switch (operation) { case BEGIN: // initialize sequencer and cherry-pick steps if there are // more commits to cherry-pick steps = prepareCommand(head); // apply the selected steps applySteps(steps, false); break; case ABORT: // delete the sequencer and reset to the original head if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING || repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) { if (originalCommit == null) { // maybe the sequencer is not created in that case simply reset to HEAD originalCommit = head; } } Utils.deleteRecursively(getSequencerFolder()); if (originalCommit != null) { ResetCommand reset = new ResetCommand(repository, getClassFactory(), originalCommit.name(), GitClient.ResetType.HARD, new DelegatingGitProgressMonitor(monitor), listener); reset.execute(); } result = createCustomResult(GitCherryPickResult.CherryPickStatus.ABORTED); break; case QUIT: // used to reset the sequencer only Utils.deleteRecursively(getSequencerFolder()); switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK); break; } break; case CONTINUE: switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts, cannot continue result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: // cannot continue without manual commit result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: // read steps from sequencer and apply them // if sequencer is empty this will be a noop steps = readTodoFile(repository); applySteps(steps, true); break; } break; default: throw new IllegalStateException("Unexpected operation " + operation.name()); } } catch (GitAPIException | IOException ex) { throw new GitException(ex); } }
Example #4
Source File: GitEnumsStateTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRepositoryState () { for (RepositoryState state : RepositoryState.values()) { assertNotNull(GitRepositoryState.getStateFor(state)); } }
Example #5
Source File: RepositoryManagementServiceInternalImpl.java From studio with GNU General Public License v3.0 | 4 votes |
@Override public boolean resolveConflict(String siteId, String path, String resolution) throws CryptoException, ServiceLayerException { GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration); Repository repo = helper.getRepository(siteId, SANDBOX); try (Git git = new Git(repo)) { switch (resolution.toLowerCase()) { case "ours" : logger.debug("Resolve conflict using OURS strategy for site " + siteId + " and path " + path); logger.debug("Reset merge conflict in git index"); git.reset().addPath(helper.getGitPath(path)).call(); logger.debug("Checkout content from HEAD of studio repository"); git.checkout().addPath(helper.getGitPath(path)).setStartPoint(Constants.HEAD).call(); break; case "theirs" : logger.debug("Resolve conflict using THEIRS strategy for site " + siteId + " and path " + path); logger.debug("Reset merge conflict in git index"); git.reset().addPath(helper.getGitPath(path)).call(); logger.debug("Checkout content from merge HEAD of remote repository"); List<ObjectId> mergeHeads = repo.readMergeHeads(); ObjectId mergeCommitId = mergeHeads.get(0); git.checkout().addPath(helper.getGitPath(path)).setStartPoint(mergeCommitId.getName()).call(); break; default: throw new ServiceLayerException("Unsupported resolution strategy for repository conflicts"); } if (repo.getRepositoryState() == RepositoryState.MERGING_RESOLVED) { logger.debug("Merge resolved. Check if there are no uncommitted changes (repo is clean)"); Status status = git.status().call(); if (!status.hasUncommittedChanges()) { logger.debug("Repository is clean. Committing to complete merge"); String userName = securityService.getCurrentUser(); User user = userServiceInternal.getUserByIdOrUsername(-1, userName); PersonIdent personIdent = helper.getAuthorIdent(user); git.commit() .setAllowEmpty(true) .setMessage("Merge resolved. Repo is clean (no changes)") .setAuthor(personIdent) .call(); } } } catch (GitAPIException | IOException | UserNotFoundException | ServiceLayerException e) { logger.error("Error while resolving conflict for site " + siteId + " using " + resolution + " resolution " + "strategy", e); throw new ServiceLayerException("Error while resolving conflict for site " + siteId + " using " + resolution + " resolution " + "strategy", e); } return true; }
Example #6
Source File: GitClient.java From netbeans with Apache License 2.0 | 2 votes |
/** * Returns the current state of the repository this client is associated with. * The state indicates what commands may be run on the repository and if the repository * requires any additional commands to get into the normal state. * @param monitor progress monitor * @return current repository state * @throws GitException an unexpected error occurs */ public GitRepositoryState getRepositoryState (ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); RepositoryState state = repository.getRepositoryState(); return GitRepositoryState.getStateFor(state); }