List of usage examples for org.eclipse.jgit.api Status getConflictingStageState
public Map<String, StageState> getConflictingStageState()
From source file:com.buildautomation.jgit.api.ListUncommittedChanges.java
License:Apache License
public static void listUncommittedChanges() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { System.out.println("Listing uncommitted changes:"); try (Git git = new Git(repository)) { Status status = git.status().call(); Set<String> conflicting = status.getConflicting(); for (String conflict : conflicting) { System.out.println("Conflicting: " + conflict); }/*from ww w.j av a 2 s.c o m*/ Set<String> added = status.getAdded(); for (String add : added) { System.out.println("Added: " + add); } Set<String> changed = status.getChanged(); for (String change : changed) { System.out.println("Change: " + change); } Set<String> missing = status.getMissing(); for (String miss : missing) { System.out.println("Missing: " + miss); } Set<String> modified = status.getModified(); for (String modify : modified) { System.out.println("Modification: " + modify); } Set<String> removed = status.getRemoved(); for (String remove : removed) { System.out.println("Removed: " + remove); } Set<String> uncommittedChanges = status.getUncommittedChanges(); for (String uncommitted : uncommittedChanges) { System.out.println("Uncommitted: " + uncommitted); } Set<String> untracked = status.getUntracked(); for (String untrack : untracked) { System.out.println("Untracked: " + untrack); } Set<String> untrackedFolders = status.getUntrackedFolders(); for (String untrack : untrackedFolders) { System.out.println("Untracked Folder: " + untrack); } Map<String, StageState> conflictingStageState = status.getConflictingStageState(); for (Map.Entry<String, StageState> entry : conflictingStageState.entrySet()) { System.out.println("ConflictingState: " + entry); } } } }
From source file:com.buildautomation.jgit.api.ShowStatus.java
License:Apache License
public static void showStatus() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { Status status = git.status().call(); System.out.println("Added: " + status.getAdded()); System.out.println("Changed: " + status.getChanged()); System.out.println("Conflicting: " + status.getConflicting()); System.out.println("ConflictingStageState: " + status.getConflictingStageState()); System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex()); System.out.println("Missing: " + status.getMissing()); System.out.println("Modified: " + status.getModified()); System.out.println("Removed: " + status.getRemoved()); System.out.println("Untracked: " + status.getUntracked()); System.out.println("UntrackedFolders: " + status.getUntrackedFolders()); }//from w ww.ja va 2s.c o m } }
From source file:edu.nju.cs.inform.jgit.porcelain.ListUncommittedChanges.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { System.out.println("Listing uncommitted changes:"); try (Git git = new Git(repository)) { Status status = git.status().call(); Set<String> conflicting = status.getConflicting(); for (String conflict : conflicting) { System.out.println("Conflicting: " + conflict); }// w w w. j a v a2s .c om Set<String> added = status.getAdded(); for (String add : added) { System.out.println("Added: " + add); } Set<String> changed = status.getChanged(); for (String change : changed) { System.out.println("Change: " + change); } Set<String> missing = status.getMissing(); for (String miss : missing) { System.out.println("Missing: " + miss); } Set<String> modified = status.getModified(); for (String modify : modified) { System.out.println("Modification: " + modify); } Set<String> removed = status.getRemoved(); for (String remove : removed) { System.out.println("Removed: " + remove); } Set<String> uncommittedChanges = status.getUncommittedChanges(); for (String uncommitted : uncommittedChanges) { System.out.println("Uncommitted: " + uncommitted); } Set<String> untracked = status.getUntracked(); for (String untrack : untracked) { System.out.println("Untracked: " + untrack); } Set<String> untrackedFolders = status.getUntrackedFolders(); for (String untrack : untrackedFolders) { System.out.println("Untracked Folder: " + untrack); } Map<String, StageState> conflictingStageState = status.getConflictingStageState(); for (Map.Entry<String, StageState> entry : conflictingStageState.entrySet()) { System.out.println("ConflictingState: " + entry); } } } }
From source file:edu.nju.cs.inform.jgit.porcelain.ShowStatus.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { Status status = git.status().call(); System.out.println("Added: " + status.getAdded()); System.out.println("Changed: " + status.getChanged()); System.out.println("Conflicting: " + status.getConflicting()); System.out.println("ConflictingStageState: " + status.getConflictingStageState()); System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex()); System.out.println("Missing: " + status.getMissing()); System.out.println("Modified: " + status.getModified()); System.out.println("Removed: " + status.getRemoved()); System.out.println("Untracked: " + status.getUntracked()); System.out.println("UntrackedFolders: " + status.getUntrackedFolders()); }//from w ww . j a v a 2 s . c om } }
From source file:edu.wustl.lookingglass.community.CommunityRepository.java
License:Open Source License
private void resolveMerge() throws NoWorkTreeException, GitAPIException, IOException { assert this.username != null; assert this.email != null; Status status = this.git.status().call(); Map<String, StageState> conflicting = status.getConflictingStageState(); for (String path : conflicting.keySet()) { StageState stageState = conflicting.get(path); switch (stageState) { case BOTH_MODIFIED: // UU case BOTH_ADDED: // AA case ADDED_BY_US: // AU case ADDED_BY_THEM: // UA // Both the local and server version have been modified File conflictingFile = new File(this.repoDir, path); String fullPath = conflictingFile.getAbsolutePath(); // Since the local copy was modified it probably makes sense to leave it // since that's the copy the user has been working on. Here's my assumption... // a sync didn't happen, so the user opens their project and sees it's not their // latest changes, they accept the failure and start to fix it... finally a sync // happens... at this point they are probably editing this world, so when they save // they wouldn't even load the new file, so we should just keep the old file. // TODO: we should really prompt the user to resolve this conflict. // but that's kinda hard with the singletons... because you probably just want // to open both files in two different windows (editors) but we can't do that. :( // Recover server version this.git.checkout().setStage(Stage.THEIRS).addPath(path).call(); // Append a timestamp LocalDateTime date = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-mm-dd+HH'h'MM'm'"); String timestamp = date.format(formatter); File theirFile = new File(FilenameUtils.getFullPath(fullPath), FilenameUtils.getBaseName(path) + " (" + timestamp + ")." + FilenameUtils.getExtension(path)); if (conflictingFile.exists() && !theirFile.exists()) { Files.move(conflictingFile.toPath(), theirFile.toPath()); String relativePath = this.repoDir.toURI().relativize(theirFile.toURI()).getPath(); this.git.add().addFilepattern(relativePath).call(); }//w w w . j av a 2 s . c o m // Recover local version this.git.checkout().setStage(Stage.OURS).addPath(path).call(); this.git.add().addFilepattern(path).call(); break; case DELETED_BY_US: // DU // The modified local version is already in the checkout, so it just needs to be added. // We need to specifically mention the file, so we can't reuse the Add () method this.git.add().addFilepattern(path).call(); break; case DELETED_BY_THEM: // UD // Recover server version this.git.checkout().setStage(Stage.THEIRS).addPath(path).call(); this.git.add().addFilepattern(path).call(); break; case BOTH_DELETED: // DD break; default: throw new IllegalArgumentException("Unknown StageState: " + stageState); } } RepositoryState resolvedState = this.git.getRepository().getRepositoryState(); assert resolvedState == RepositoryState.MERGING_RESOLVED; // we are done resolving the merge! this.git.commit().setAuthor(this.username, this.email).call(); RepositoryState safeState = this.git.getRepository().getRepositoryState(); assert safeState == RepositoryState.SAFE; }
From source file:org.apache.openaz.xacml.admin.model.GitStatusContainer.java
License:Apache License
public void refreshStatus(Status status) { ///*from w w w . j av a 2 s .c o m*/ // Save this // this.conflictingStage = status.getConflictingStageState(); if (logger.isDebugEnabled()) { logger.debug("conflictingStage: " + this.conflictingStage.size()); } // // Re-create this // this.map = new TreeMap<String, GitEntry>(); this.conflictCount = 0; // // Iterate through everything // for (String id : status.getAdded()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setAdded(true); } for (String id : status.getChanged()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setChanged(true); } for (String id : status.getConflicting()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setConflicting(true); // // // conflictCount++; } for (String id : status.getMissing()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setMissing(true); } for (String id : status.getModified()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setModified(true); } for (String id : status.getRemoved()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setRemoved(true); } for (String id : status.getUncommittedChanges()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setUncommitted(true); } for (String id : status.getUntracked()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setUntracked(true); } for (String id : status.getUntrackedFolders()) { if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) { continue; } GitEntry entry = this.map.get(id); if (entry == null) { entry = new GitEntry(id); this.map.put(id, entry); } entry.setUntrackedFolders(true); } }
From source file:org.commonjava.aprox.subsys.git.GitManager.java
License:Apache License
public GitManager commitModifiedFiles(final ChangeSummary changeSummary) throws GitSubsystemException { Status status; try {//from www. ja v a 2s .c o m status = git.status().call(); } catch (NoWorkTreeException | GitAPIException e) { throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage()); } final Map<String, StageState> css = status.getConflictingStageState(); if (!css.isEmpty()) { throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n %s", rootDir, new JoinString("\n ", css.entrySet())); } final Set<String> toAdd = new HashSet<>(); final Set<String> modified = status.getModified(); if (modified != null && !modified.isEmpty()) { toAdd.addAll(modified); } final Set<String> untracked = status.getUntracked(); if (untracked != null && !untracked.isEmpty()) { toAdd.addAll(untracked); } final Set<String> untrackedFolders = status.getUntrackedFolders(); if (untrackedFolders != null && !untrackedFolders.isEmpty()) { toAdd.addAll(untrackedFolders); // for ( String folderPath : untrackedFolders ) // { // File dir = new File( rootDir, folderPath ); // Files.walkFileTree( null, null ) // } } if (!toAdd.isEmpty()) { addAndCommitPaths(changeSummary, toAdd); } return this; }
From source file:org.commonjava.indy.subsys.git.GitManager.java
License:Apache License
private Status getStatus() throws GitSubsystemException { Status status; try {/*from ww w . j av a2 s. c o m*/ status = git.status().call(); } catch (NoWorkTreeException | GitAPIException e) { throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage()); } final Map<String, StageState> css = status.getConflictingStageState(); if (!css.isEmpty()) { throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n %s", rootDir, new JoinString("\n ", css.entrySet())); } return status; }
From source file:org.eclipse.emf.compare.ide.ui.tests.merge.StrategyRecursiveModelTest.java
License:Open Source License
/** * This test will initialize a repository with two branches with a few changes each, then try to merge the * branch into master./*from w ww . ja va2 s . co m*/ * <p> * The repository will contain two files, file1.sample and file2.sample, both being in the same container * and thus considered to be components of a single logical model by the SampleModelProvider. * </p> * <p> * file1 will be modified on both master and the branch in such a way that it will be an unresolveable * conflict for both JGit and the model merger. file2 will be deleted from the branch. * </p> * <p> * The merge must end in a conflict. The SampleResourceMappingMerger pre-merges what can be, so file2 will * be deleted from the working tree while file1 will be left untouched. file2 will be added to the index, * but file 1 will be marked as a conflict. * </p> * * @throws Exception */ @Test public void mergeModelWithDeletedRemoteModelConflict() throws Exception { File file1 = repository.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION); //$NON-NLS-1$ File file2 = repository.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION); //$NON-NLS-1$ repository.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_FILE1, "first file - initial commit"); //$NON-NLS-1$ repository.appendContentAndCommit(iProject, file2, INITIAL_CONTENT_FILE2, "second file - initial commit"); //$NON-NLS-1$ IFile iFile1 = repository.getIFile(iProject, file1); IFile iFile2 = repository.getIFile(iProject, file2); String repoRelativePath1 = repository.getRepoRelativePath(iFile1.getLocation().toPortableString()); String repoRelativePath2 = repository.getRepoRelativePath(iFile2.getLocation().toPortableString()); repository.createAndCheckoutBranch(MASTER, BRANCH); setContentsAndCommit(repository, iFile1, BRANCH_CHANGE + INITIAL_CONTENT_FILE1, "branch commit"); //$NON-NLS-1$ iFile2.delete(true, new NullProgressMonitor()); repository.addAndCommit(iProject, "branch commit - deleted file2." + SAMPLE_FILE_EXTENSION, file2); //$NON-NLS-1$ repository.checkoutBranch(MASTER); setContentsAndCommit(repository, iFile1, MASTER_CHANGE + INITIAL_CONTENT_FILE1, "master commit"); //$NON-NLS-1$ iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // end setup merge(repo, BRANCH); final Status status = status(repo); assertTrue(status.hasUncommittedChanges()); assertFalse(status.getConflicting().isEmpty()); assertTrue(status.getConflicting().contains(repoRelativePath1)); assertTrue(status.getRemoved().contains(repoRelativePath2)); assertContentEquals(iFile1, MASTER_CHANGE + INITIAL_CONTENT_FILE1); assertFalse(iFile2.exists()); Map<String, StageState> map = status.getConflictingStageState(); assertEquals(StageState.BOTH_MODIFIED, map.get(repoRelativePath1)); }
From source file:org.eclipse.emf.compare.ide.ui.tests.merge.StrategyRecursiveModelTest.java
License:Open Source License
/** * This test will initialize a repository with two branches with a few changes each, then try to merge the * branch into master./*from ww w . j ava 2 s. com*/ * <p> * The repository will contain two files, file1.sample and file2.sample, both being in the same container * and thus considered to be components of a single logical model by the SampleModelProvider. * </p> * <p> * file1 will be modified on both master and the branch in such a way that it will be an unresolveable * conflict for both JGit and the model merger. file2 will be deleted from master. * </p> * <p> * The merge must end in a conflict. Since file2 has been deleted locally and has not been changed on the * remote, it will not be seen as a part of the logical model (it won't even be part of the merge * operation). Thus, file1 will be marked as a conflict, untouched as compared to its previous (master) * state, and file2 will not be part of the index. * </p> * * @throws Exception */ @Test public void mergeModelWithDeletedLocalModelConflict() throws Exception { File file1 = repository.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION); //$NON-NLS-1$ File file2 = repository.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION); //$NON-NLS-1$ repository.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_FILE1, "first file - initial commit"); //$NON-NLS-1$ repository.appendContentAndCommit(iProject, file2, INITIAL_CONTENT_FILE2, "second file - initial commit"); //$NON-NLS-1$ IFile iFile1 = repository.getIFile(iProject, file1); IFile iFile2 = repository.getIFile(iProject, file2); String repoRelativePath1 = repository.getRepoRelativePath(iFile1.getLocation().toPortableString()); String repoRelativePath2 = repository.getRepoRelativePath(iFile2.getLocation().toPortableString()); repository.createAndCheckoutBranch(MASTER, BRANCH); setContentsAndCommit(repository, iFile1, BRANCH_CHANGE + INITIAL_CONTENT_FILE1, "branch commit"); //$NON-NLS-1$ repository.checkoutBranch(MASTER); setContentsAndCommit(repository, iFile1, MASTER_CHANGE + INITIAL_CONTENT_FILE1, "master commit"); //$NON-NLS-1$ iFile2.delete(true, new NullProgressMonitor()); repository.addAndCommit(iProject, "master commit - deleted file2." + SAMPLE_FILE_EXTENSION, file2); //$NON-NLS-1$ iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // end setup merge(repo, BRANCH); final Status status = status(repo); assertTrue(status.hasUncommittedChanges()); assertFalse(status.getConflicting().isEmpty()); assertTrue(status.getConflicting().contains(repoRelativePath1)); assertFalse(status.getConflicting().contains(repoRelativePath2)); assertContentEquals(iFile1, MASTER_CHANGE + INITIAL_CONTENT_FILE1); assertFalse(iFile2.exists()); Map<String, StageState> map = status.getConflictingStageState(); assertEquals(StageState.BOTH_MODIFIED, map.get(repoRelativePath1)); }