List of usage examples for org.eclipse.jgit.treewalk NameConflictTreeWalk NameConflictTreeWalk
public NameConflictTreeWalk(ObjectReader or)
From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java
License:Eclipse Distribution License
/** * The resolve conflict way of three way merging * * @param baseTree/* w w w . ja va 2 s . com*/ * @param headTree * @param mergeTree * @param ignoreConflicts * Controls what to do in case a content-merge is done and a * conflict is detected. The default setting for this should be * <code>false</code>. In this case the working tree file is * filled with new content (containing conflict markers) and the * index is filled with multiple stages containing BASE, OURS and * THEIRS content. Having such non-0 stages is the sign to git * tools that there are still conflicts for that path. * <p> * If <code>true</code> is specified the behavior is different. * In case a conflict is detected the working tree file is again * filled with new content (containing conflict markers). But * also stage 0 of the index is filled with that content. No * other stages are filled. Means: there is no conflict on that * path but the new content (including conflict markers) is * stored as successful merge result. This is needed in the * context of {@link RecursiveMerger} where when determining * merge bases we don't want to deal with content-merge * conflicts. * @return whether the trees merged cleanly * @throws IOException * @since 3.5 */ @Override protected boolean mergeTrees(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree, boolean ignoreConflicts) throws IOException { this.builder = this.dircache.builder(); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(this.builder); this.tw = new NameConflictTreeWalk(this.reader); this.tw.addTree(baseTree); this.tw.addTree(headTree); this.tw.addTree(mergeTree); this.tw.addTree(buildIt); if (this.workingTreeIterator != null) { this.tw.addTree(this.workingTreeIterator); } else { this.tw.setFilter(TreeFilter.ANY_DIFF); } if (!mergeTreeWalk(this.tw, ignoreConflicts)) { return false; } if (!this.inCore) { // No problem found. The only thing left to be done is to // checkout all files from "theirs" which have been selected to // go into the new index. checkout(); // All content-merges are successfully done. If we can now write the // new index we are on quite safe ground. Even if the checkout of // files coming from "theirs" fails the user can work around such // failures by checking out the index again. if (!this.builder.commit()) { cleanUp(); throw new IndexWriteException(); } this.builder = null; } else { this.builder.finish(); this.builder = null; } if (getUnmergedPaths().isEmpty() && !failed()) { this.resultTree = this.dircache.writeTree(getObjectInserter()); return true; } else { this.resultTree = null; return false; } }
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareAddCommand.java
@Override public DirCache call() throws GitAPIException { if (filepatterns.isEmpty()) { throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); }//ww w. j a v a 2 s . c om checkCallable(); boolean addAll = filepatterns.contains("."); //$NON-NLS-1$ try (ObjectInserter inserter = repo.newObjectInserter(); NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) { tw.setOperationType(OperationType.CHECKIN_OP); dirCache.lock(); DirCacheBuilder builder = dirCache.builder(); tw.addTree(new DirCacheBuildIterator(builder)); if (workingTreeIterator == null) workingTreeIterator = new FileTreeIterator(repo); workingTreeIterator.setDirCacheIterator(tw, 0); tw.addTree(workingTreeIterator); if (!addAll) { tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); } byte[] lastAdded = null; while (tw.next()) { DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class); if (c == null && f != null && f.isEntryIgnored()) { // file is not in index but is ignored, do nothing continue; } else if (c == null && update) { // Only update of existing entries was requested. continue; } DirCacheEntry entry = c != null ? c.getDirCacheEntry() : null; if (entry != null && entry.getStage() > 0 && lastAdded != null && lastAdded.length == tw.getPathLength() && tw.isPathPrefix(lastAdded, lastAdded.length) == 0) { // In case of an existing merge conflict the // DirCacheBuildIterator iterates over all stages of // this path, we however want to add only one // new DirCacheEntry per path. continue; } if (tw.isSubtree() && !tw.isDirectoryFileConflict()) { tw.enterSubtree(); continue; } if (f == null) { // working tree file does not exist if (entry != null && (!update || GITLINK == entry.getFileMode())) { builder.add(entry); } continue; } if (entry != null && entry.isAssumeValid()) { // Index entry is marked assume valid. Even though // the user specified the file to be added JGit does // not consider the file for addition. builder.add(entry); continue; } if ((f.getEntryRawMode() == TYPE_TREE && f.getIndexFileMode(c) != FileMode.GITLINK) || (f.getEntryRawMode() == TYPE_GITLINK && f.getIndexFileMode(c) == FileMode.TREE)) { // Index entry exists and is symlink, gitlink or file, // otherwise the tree would have been entered above. // Replace the index entry by diving into tree of files. tw.enterSubtree(); continue; } byte[] path = tw.getRawPath(); if (entry == null || entry.getStage() > 0) { entry = new DirCacheEntry(path); } FileMode mode = f.getIndexFileMode(c); entry.setFileMode(mode); if (GITLINK != mode) { entry.setLength(f.getEntryLength()); entry.setLastModified(f.getEntryLastModified()); long len = f.getEntryContentLength(); try (InputStream in = f.openEntryStream()) { ObjectId id = inserter.insert(OBJ_BLOB, len, in); entry.setObjectId(id); } } else { entry.setLength(0); entry.setLastModified(0); entry.setObjectId(f.getEntryObjectId()); } builder.add(entry); lastAdded = path; } inserter.flush(); builder.commit(); setCallable(false); } catch (IOException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof FilterFailedException) throw (FilterFailedException) cause; throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e); } finally { if (dirCache != null) { dirCache.unlock(); } } return dirCache; }
From source file:com.microsoft.gittf.core.tasks.CreateCommitForPendingSetsTask.java
License:Open Source License
@Override public TaskStatus run(final TaskProgressMonitor progressMonitor) { progressMonitor.beginTask(getProgressMonitorMessage(), 1, TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL); ObjectInserter repositoryInserter = null; TreeWalk treeWalker = null;/*from w w w .ja v a2 s . c o m*/ RevWalk walk = null; try { validateTempDirectory(); Item rootServerItem = versionControlService.getItem(serverPath, LatestVersionSpec.INSTANCE, DeletedState.NON_DELETED, GetItemsOptions.NONE); String serverPathToUse = rootServerItem.getServerItem(); Set<String> pendingSetItemPath = new TreeSet<String>(); Map<String, PendingChange> pendingSetMap = new HashMap<String, PendingChange>(); PendingSet[] pendingSets = getPendingSets(); /* * keep track of the items added, renamed and folders renamed for * special handling later */ Set<String> itemsAddedInPendingSet = new TreeSet<String>(); Set<String> itemsRenamedInPendingSet = new TreeSet<String>(); Set<String> itemsDeletedInPendingSet = new TreeSet<String>(); Set<String> foldersRenamedInPendingSet = new TreeSet<String>(Collections.reverseOrder()); Set<String> foldersDeletedInPendingSet = new TreeSet<String>(); progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsProcessedFromPendingSets")); //$NON-NLS-1$ for (PendingSet set : pendingSets) { for (PendingChange change : set.getPendingChanges()) { String serverItem = change.getServerItem(); String sourceServerItem = change.getSourceServerItem() != null ? change.getSourceServerItem() : null; String pathToUse = serverItem; ChangeType changeType = change.getChangeType(); if (change.getItemType() == ItemType.FILE) { if (changeType.contains(ChangeType.ADD) || changeType.contains(ChangeType.BRANCH) || changeType.contains(ChangeType.UNDELETE)) { itemsAddedInPendingSet.add(serverItem); } else if (changeType.contains(ChangeType.RENAME)) { itemsRenamedInPendingSet.add(sourceServerItem); pathToUse = sourceServerItem; } else if (changeType.contains(ChangeType.DELETE)) { itemsDeletedInPendingSet.add(serverItem); } else { /* * in case there is a source server item use that. * This will be true in the case of a file edit and * its parent has been renamed */ if (change.getSourceServerItem() != null) { pathToUse = sourceServerItem; } } } else if (change.getItemType() == ItemType.FOLDER) { if (changeType.contains(ChangeType.RENAME)) { foldersRenamedInPendingSet.add(sourceServerItem); pathToUse = sourceServerItem; } else if (changeType.contains(ChangeType.DELETE)) { foldersDeletedInPendingSet.add(serverItem); } } progressMonitor.displayVerbose(pathToUse); pendingSetItemPath.add(pathToUse); pendingSetMap.put(pathToUse, change); } } progressMonitor.displayVerbose(""); //$NON-NLS-1$ progressMonitor.setWork(pendingSetItemPath.size()); repositoryInserter = repository.newObjectInserter(); treeWalker = new NameConflictTreeWalk(repository); walk = new RevWalk(repository); ObjectId baseCommitId = parentCommitID; if (baseCommitId == null) { ChangesetCommitMap commitMap = new ChangesetCommitMap(repository); baseCommitId = commitMap.getCommitID(commitMap.getLastBridgedChangesetID(true), false); } RevCommit parentCommit = walk.parseCommit(baseCommitId); if (parentCommit == null) { throw new Exception( Messages.getString("CreateCommitForPendingSetsTask.LatestDownloadedChangesetNotFound")); //$NON-NLS-1$ } RevTree baseCommitTree = parentCommit.getTree(); /* * We want trees sorted by children first so we can simply walk them * (child-first) to build the hierarchy once we've finished * inserting blobs. */ final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> baseTreeHeirarchy = new TreeMap<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>>( new CommitTreePathComparator()); final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> pendingSetTreeHeirarchy = new TreeMap<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>>( new CommitTreePathComparator()); treeWalker.setRecursive(true); treeWalker.addTree(baseCommitTree); /* * Phase one: build the pending set commit tree by copying the * parent tree */ progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsDownloadedFromPendingSets")); //$NON-NLS-1$ while (treeWalker.next()) { String itemServerPath = ServerPath.combine(serverPathToUse, treeWalker.getPathString()); /* if the item has a pending change apply the pending change */ if (pendingSetItemPath.contains(itemServerPath)) { progressMonitor.displayVerbose(itemServerPath); if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, pendingSetMap.get(itemServerPath), true, progressMonitor); } if (!itemsDeletedInPendingSet.contains(itemServerPath) && !itemsRenamedInPendingSet.contains(itemServerPath)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, pendingSetMap.get(itemServerPath), false, progressMonitor); } progressMonitor.worked(1); } /* if the item parent is renamed handle this case */ else if (isParentInCollection(foldersRenamedInPendingSet, itemServerPath)) { if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } String destinationServerItem = updateServerItemWithParentRename(foldersRenamedInPendingSet, itemServerPath, pendingSetMap); if (ServerPath.isChild(serverPathToUse, destinationServerItem)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, destinationServerItem, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } } /* * add all other items to the tree unless their parent was * deleted */ else { if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } if (!isParentInCollection(foldersDeletedInPendingSet, itemServerPath)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } } } progressMonitor.displayVerbose(""); //$NON-NLS-1$ /* for items that were added in the shelveset add those here */ progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsDownloadedFromPendingSetsAdds")); //$NON-NLS-1$ for (String newItem : itemsAddedInPendingSet) { if (!ServerPath.isChild(serverPathToUse, newItem)) { // Ignore files that are added that are not mapped in the // repository continue; } progressMonitor.displayVerbose(newItem); createBlob(repositoryInserter, pendingSetTreeHeirarchy, pendingSetMap.get(newItem), false, progressMonitor); progressMonitor.worked(1); } for (String renamedItem : itemsRenamedInPendingSet) { PendingChange change = pendingSetMap.get(renamedItem); if (!ServerPath.isChild(serverPathToUse, change.getServerItem())) { // Ignore files that are renamed to server items that are // outside the repository continue; } progressMonitor.displayVerbose(renamedItem); createBlob(repositoryInserter, pendingSetTreeHeirarchy, change, false, progressMonitor); progressMonitor.worked(1); } progressMonitor.displayVerbose(""); //$NON-NLS-1$ /* Phase two: add child trees to their parents. */ progressMonitor.setDetail(Messages.getString("CreateCommitTask.CreatingTrees")); //$NON-NLS-1$ ObjectId rootBaseTree = createStashCommit ? createTrees(repositoryInserter, baseTreeHeirarchy) : null; ObjectId rootPendingSetTree = createTrees(repositoryInserter, pendingSetTreeHeirarchy); /* Phase three: create the commit. */ progressMonitor.setDetail(Messages.getString("CreateCommitTask.CreatingCommit")); //$NON-NLS-1$ if (createStashCommit) { this.commitId = StashUtil.create(repository, repositoryInserter, rootBaseTree, rootPendingSetTree, rootBaseTree, parentCommitID, getOwnerDisplayName(), getOwner(), getComment(), getName()); } else { this.commitId = createCommit(repositoryInserter, rootPendingSetTree, parentCommitID); } progressMonitor.endTask(); return TaskStatus.OK_STATUS; } catch (Exception e) { log.error(e); return new TaskStatus(TaskStatus.ERROR, e); } finally { FileHelpers.deleteDirectory(tempDir); if (repositoryInserter != null) { repositoryInserter.release(); } if (treeWalker != null) { treeWalker.release(); } if (walk != null) { walk.release(); } } }
From source file:com.microsoft.gittf.core.tasks.pendDiff.PendDifferenceTask.java
License:Open Source License
/** * Validates that the commit tree does not have the any item twice with the * same name only different in case. TFS does not support having the same * item with different case so we should not allow that. * /*from w w w .ja v a 2 s. co m*/ * @param commit * @throws Exception */ private void validateCaseSensitivityRequirements(RevCommit commit) throws Exception { /* Create a tree walker */ RevTree tree = commit.getTree(); final TreeWalk treeWalker = new NameConflictTreeWalk(repository); try { treeWalker.addTree(tree); treeWalker.setFilter(TreeFilter.ALL); /* * Build a list of items in the tree in a hash set for quicker * lookup */ Set<String> existingTreeItems = new HashSet<String>(); /* Walk the tree looking for duplicates in the tree */ while (treeWalker.next()) { String pathString = treeWalker.getPathString().toLowerCase(); if (existingTreeItems.contains(pathString)) { throw new Exception( Messages.formatString("PendDifferenceTask.SimilarItemWithDifferentCaseInCommitFormat", //$NON-NLS-1$ pathString, ObjectIdUtil.abbreviate(repository, commit.getId()))); } existingTreeItems.add(pathString); int objectType = treeWalker.getFileMode(0).getObjectType(); if (objectType == OBJ_TREE) { treeWalker.enterSubtree(); } } } finally { if (treeWalker != null) { treeWalker.release(); } } }
From source file:com.microsoft.gittf.core.tasks.pendDiff.PendDifferenceTask.java
License:Open Source License
/** * Creates the CheckinAnalysisChangeCollection analysis object that includes * the list of pending changes needed that map to the differences between * the fromCommit and toCommit// w w w .ja va2s. c om * * @param repository * the git repository * @param fromRootTree * the from commit tree * @param toRootTree * the to commit tree * @param renameMode * the rename mode to use when generating the analysis * @param progressMonitor * the progress monitor to use to report progress * @return * @throws Exception */ public static CheckinAnalysisChangeCollection analyzeDifferences(Repository repository, RevObject fromRootTree, RevObject toRootTree, RenameMode renameMode, final TaskProgressMonitor progressMonitor) throws Exception { Check.notNull(fromRootTree, "fromRootTree"); //$NON-NLS-1$ Check.notNull(toRootTree, "toRootTree"); //$NON-NLS-1$ Check.notNull(progressMonitor, "progressMonitor"); //$NON-NLS-1$ progressMonitor.beginTask(Messages.getString("PendDifferencesTask.AnalyzingCommits"), //$NON-NLS-1$ TaskProgressMonitor.INDETERMINATE, TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL); /* Init the analysis object */ final CheckinAnalysisChangeCollection analysis = new CheckinAnalysisChangeCollection(repository, fromRootTree, toRootTree); log.debug("Walking thru the git-repository tree."); /* Init the tree walker object */ final TreeWalk treeWalker = new NameConflictTreeWalk(repository); final RenameDetector repositoryRenameDetector = new RenameDetector(repository); try { treeWalker.setRecursive(true); treeWalker.addTree(fromRootTree); treeWalker.addTree(toRootTree); treeWalker.setFilter(TreeFilter.ANY_DIFF); List<DiffEntry> treeDifferences = DiffEntry.scan(treeWalker); log.debug("The number of differences found: " + treeDifferences.size()); /* * If we need to detect file renames then use the rename detector to * analayze the differences first */ if (renameMode != RenameMode.NONE) { repositoryRenameDetector.addAll(treeDifferences); treeDifferences = repositoryRenameDetector.compute(); } /* * If the rename mode is either none or file only then we do not * need to detect folder deletes as well, since deleting empty * folders that have items that have been renamed out is not * supported in TFS */ if (renameMode != RenameMode.ALL) { analysis.setProcessDeletedFolders(false); } Map<String, DiffEntry> deleteChanges = new HashMap<String, DiffEntry>(); Map<String, DiffEntry> addChanges = new HashMap<String, DiffEntry>(); for (DiffEntry change : treeDifferences) { switch (change.getChangeType()) { case ADD: addChanges.put(change.getNewPath().toUpperCase(), change); break; case DELETE: deleteChanges.put(change.getOldPath().toUpperCase(), change); break; } } /* Append each change in to the analysis object */ for (DiffEntry change : treeDifferences) { switch (change.getChangeType()) { case ADD: case COPY: if (!isCaseSensitiveRename(change, deleteChanges, addChanges)) { analysis.pendAdd(new AddChange(change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()))); analysis.pendPropertyIfChanged(new PropertyChange(change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()), change.getNewMode())); } break; case DELETE: if (isCaseSensitiveRename(change, deleteChanges, addChanges)) { DiffEntry addChange = addChanges.get(change.getOldPath().toUpperCase()); analysis.pendRename(new RenameChange(change.getOldPath(), addChange.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, addChange.getNewId()), !change.getOldId().equals(addChange.getNewId()))); analysis.pendPropertyIfChanged(new PropertyChange(addChange.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, addChange.getNewId()), change.getOldMode(), addChange.getNewMode())); } else { analysis.pendDelete(new DeleteChange(change.getOldPath(), change.getOldMode())); } break; case MODIFY: analysis.pendEdit(new EditChange(change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()))); analysis.pendPropertyIfChanged(new PropertyChange(change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()), change.getOldMode(), change.getNewMode())); break; case RENAME: analysis.pendRename(new RenameChange(change.getOldPath(), change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()), !change.getOldId().equals(change.getNewId()))); analysis.pendPropertyIfChanged(new PropertyChange(change.getNewPath(), CommitUtil.resolveAbbreviatedId(repository, change.getNewId()), change.getOldMode(), change.getNewMode())); } } } finally { if (treeWalker != null) { treeWalker.release(); } progressMonitor.endTask(); } log.debug("Walk thru the git-repository tree finished."); return analysis; }
From source file:com.microsoft.gittf.core.tasks.pendDiff.PendDifferenceTask.java
License:Open Source License
/** * Creates a CheckinAnalysisChangeCollection for the to commit tree, * creating an ADD change for every item in the tree. * /*w ww. j a v a2 s . c o m*/ * @param repository * the git repository * @param toRootTree * the to commit tree * @param progressMonitor * the progress monitor to use to report progress * @return * @throws Exception */ public static CheckinAnalysisChangeCollection analyzeTree(Repository repository, RevTree toRootTree, TaskProgressMonitor progressMonitor) throws Exception { Check.notNull(toRootTree, "toRootTree"); //$NON-NLS-1$ Check.notNull(progressMonitor, "progressMonitor"); //$NON-NLS-1$ progressMonitor.beginTask(Messages.getString("PendDifferencesTask.AnalyzingCommits"), //$NON-NLS-1$ TaskProgressMonitor.INDETERMINATE, TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL); /* Create the CheckinAnalysisChangeCollection object */ final CheckinAnalysisChangeCollection analysis = new CheckinAnalysisChangeCollection(); final TreeWalk treeWalker = new NameConflictTreeWalk(repository); log.debug("Walking thru the git-repository tree."); try { treeWalker.setRecursive(true); treeWalker.addTree(toRootTree); treeWalker.setFilter(TreeFilter.ANY_DIFF); /* Walk the tree and pend and add for every item in the tree */ while (treeWalker.next()) { final ObjectId toID = treeWalker.getObjectId(0); if (!ObjectId.zeroId().equals(toID)) { analysis.pendAdd(new AddChange(treeWalker.getPathString(), toID)); } else { log.info(MessageFormat.format("Ignoring item {0} - type {1}", //$NON-NLS-1$ treeWalker.getPathString(), (toRootTree != null ? treeWalker.getFileMode(1).getObjectType() : "none"))); //$NON-NLS-1$ } } } finally { if (treeWalker != null) { treeWalker.release(); } progressMonitor.endTask(); } log.debug("Walk thru the git-repository tree finished."); return analysis; }
From source file:com.microsoft.gittf.core.util.RepositoryUtil.java
License:Open Source License
public static void fixFileAttributes(final Repository repository) throws IOException { if (Platform.isCurrentPlatform(Platform.GENERIC_UNIX)) { final TreeWalk treeWalk = new NameConflictTreeWalk(repository); final Ref headReference = repository.getRef(Constants.HEAD); final RevCommit headCommit = new RevWalk(repository).parseCommit(headReference.getObjectId()); treeWalk.setRecursive(true);// w ww . j a v a 2 s .co m treeWalk.addTree(headCommit.getTree().getId()); treeWalk.setFilter(TreeFilter.ANY_DIFF); final File workingDirectory = repository.getWorkTree(); while (treeWalk.next()) { final FileMode fileMode = treeWalk.getFileMode(0); if (FileMode.EXECUTABLE_FILE == fileMode) { final File file = new File(workingDirectory, treeWalk.getPathString()); log.debug("Executable: " + file.getAbsolutePath()); final FileSystemAttributes attr = FileSystemUtils.getInstance().getAttributes(file); attr.setExecutable(true); FileSystemUtils.getInstance().setAttributes(file, attr); } } treeWalk.reset(); } }
From source file:org.eclipse.egit.core.internal.merge.GitResourceVariantTreeSubscriberTest.java
License:Open Source License
private GitResourceVariantTreeProvider createTreeProvider() throws Exception { testRepo.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_1, "first file - initial commit"); testRepo.appendContentAndCommit(iProject, file2, INITIAL_CONTENT_2, "second file - initial commit"); testRepo.createBranch(MASTER, BASE); testRepo.createAndCheckoutBranch(MASTER, BRANCH); setContentsAndCommit(testRepo, iFile2, BRANCH_CHANGES + INITIAL_CONTENT_2, "branch commit"); testRepo.checkoutBranch(MASTER);/*from ww w . j av a 2 s .co m*/ setContentsAndCommit(testRepo, iFile1, INITIAL_CONTENT_1 + MASTER_CHANGES, "master commit"); iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // as if we tried to merge branch into master try (RevWalk walk = new RevWalk(repo)) { RevTree baseTree = walk.parseTree(repo.resolve(BASE)); RevTree sourceTree = walk.parseTree(repo.resolve(MASTER)); RevTree remoteTree = walk.parseTree(repo.resolve(BRANCH)); TreeWalk treeWalk = new NameConflictTreeWalk(repo); treeWalk.addTree(baseTree); treeWalk.addTree(sourceTree); treeWalk.addTree(remoteTree); return new TreeWalkResourceVariantTreeProvider(repo, treeWalk, 0, 1, 2); } }
From source file:org.eclipse.egit.core.internal.merge.GitResourceVariantTreeSubscriberTest.java
License:Open Source License
private GitResourceVariantTreeProvider createTreeProviderWithAdditions() throws Exception { testRepo.createBranch(MASTER, BASE); testRepo.createAndCheckoutBranch(MASTER, BRANCH); file2 = testRepo.createFile(iProject, "file2"); testRepo.appendContentAndCommit(iProject, file2, INITIAL_CONTENT_2, "Creation of file2 in branch2."); testRepo.checkoutBranch(MASTER);//www.j a va 2 s. c o m file1 = testRepo.createFile(iProject, "file1"); testRepo.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_1, "Creation of file1 in branch1."); iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // as if we tried to merge branch3 into branch2 try (RevWalk walk = new RevWalk(repo)) { RevTree baseTree = walk.parseTree(repo.resolve(BASE)); RevTree sourceTree = walk.parseTree(repo.resolve(MASTER)); RevTree remoteTree = walk.parseTree(repo.resolve(BRANCH)); TreeWalk treeWalk = new NameConflictTreeWalk(repo); treeWalk.addTree(baseTree); treeWalk.addTree(sourceTree); treeWalk.addTree(remoteTree); return new TreeWalkResourceVariantTreeProvider(repo, treeWalk, 0, 1, 2); } }
From source file:org.eclipse.egit.core.internal.merge.GitResourceVariantTreeSubscriberTest.java
License:Open Source License
private GitResourceVariantTreeProvider createTreeProviderWithDeletions() throws Exception { file1 = testRepo.createFile(iProject, "file1"); testRepo.appendContentAndCommit(iProject, file1, INITIAL_CONTENT_1, "Creation of file1 in branch1."); file2 = testRepo.createFile(iProject, "file2"); testRepo.appendContentAndCommit(iProject, file2, INITIAL_CONTENT_2, "Creation of file2 in branch2."); testRepo.createBranch(MASTER, BASE); testRepo.createAndCheckoutBranch(MASTER, BRANCH); testRepo.untrack(file2);//ww w .j a va 2 s. co m testRepo.commit("Removed file2 in branch."); testRepo.checkoutBranch(MASTER); testRepo.untrack(file1); testRepo.commit("Removed file1 in master."); iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // as if we tried to merge branch3 into branch2 try (RevWalk walk = new RevWalk(repo)) { RevTree baseTree = walk.parseTree(repo.resolve(BASE)); RevTree sourceTree = walk.parseTree(repo.resolve(MASTER)); RevTree remoteTree = walk.parseTree(repo.resolve(BRANCH)); TreeWalk treeWalk = new NameConflictTreeWalk(repo); treeWalk.addTree(baseTree); treeWalk.addTree(sourceTree); treeWalk.addTree(remoteTree); return new TreeWalkResourceVariantTreeProvider(repo, treeWalk, 0, 1, 2); } }