@Test public void testSwitchedFileAndFolder() throws Exception { final String branchUrl = prepareBranchesStructure(); final SubTree tree = new SubTree(myWorkingCopyDir); verify(runSvn("switch", branchUrl + "/root/source/s1.txt", tree.myS1File.getPath())); verify(runSvn("switch", branchUrl + "/root/target", tree.myTargetDir.getPath())); final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); final Runnable check = new Runnable() { @Override public void run() { Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myS1File)); Assert.assertEquals(FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.myS2File)); Assert.assertEquals( FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.mySourceDir)); Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetDir)); Assert.assertEquals( FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetFiles.get(1))); } }; myScheme.doTest(check); changeListManager.ensureUpToDate(false); check.run(); editFileInCommand(myProject, tree.myS1File, "1234543534543 3543 "); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); final Runnable check2 = new Runnable() { @Override public void run() { Assert.assertEquals(FileStatus.MODIFIED, changeListManager.getStatus(tree.myS1File)); Assert.assertEquals(FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.myS2File)); Assert.assertEquals( FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.mySourceDir)); Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetDir)); Assert.assertEquals( FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetFiles.get(1))); } }; myScheme.doTest(check2); changeListManager.ensureUpToDate(false); check2.run(); }
private boolean checkIfThereAreFakeRevisions(final Project project, final Change[] changes) { boolean needsConvertion = false; for (Change change : changes) { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); if (beforeRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(beforeRevision.getFile()); needsConvertion = true; } if (afterRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(afterRevision.getFile()); needsConvertion = true; } } return needsConvertion; }
/** call in setUp */ public DuringChangeListManagerUpdateTestScheme(final Project project, final String tmpDirPath) { final MockAbstractVcs vcs = new MockAbstractVcs(project); myChangeProvider = new MockDelayingChangeProvider(); vcs.setChangeProvider(myChangeProvider); final File mockVcsRoot = new File(tmpDirPath, "mock"); mockVcsRoot.mkdir(); final VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mockVcsRoot); final ProjectLevelVcsManagerImpl projectLevelVcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project); projectLevelVcsManager.registerVcs(vcs); // projectLevelVcsManager.setDirectoryMapping(mockVcsRoot.getAbsolutePath(), vcs.getName()); final ArrayList<VcsDirectoryMapping> list = new ArrayList<VcsDirectoryMapping>(projectLevelVcsManager.getDirectoryMappings()); list.add(new VcsDirectoryMapping(vRoot.getPath(), vcs.getName())); projectLevelVcsManager.setDirectoryMappings(list); AbstractVcs vcsFound = projectLevelVcsManager.findVcsByName(vcs.getName()); final VirtualFile[] roots = projectLevelVcsManager.getRootsUnderVcs(vcsFound); assert roots.length == 1 : Arrays.asList(roots) + "; " + vcs.getName() + "; " + Arrays.toString(AllVcses.getInstance(project).getAll()); myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project); myClManager = ChangeListManager.getInstance(project); }
@Test public void testSimpleExternalsStatus() throws Exception { prepareExternal(); final File sourceFile = new File(myWorkingCopyDir.getPath(), "source" + File.separator + "s1.txt"); final File externalFile = new File( myWorkingCopyDir.getPath(), "source" + File.separator + "external" + File.separator + "t12.txt"); final LocalFileSystem lfs = LocalFileSystem.getInstance(); final VirtualFile vf1 = lfs.refreshAndFindFileByIoFile(sourceFile); final VirtualFile vf2 = lfs.refreshAndFindFileByIoFile(externalFile); Assert.assertNotNull(vf1); Assert.assertNotNull(vf2); editFileInCommand(myProject, vf1, "test externals 123" + System.currentTimeMillis()); editFileInCommand(myProject, vf2, "test externals 123" + System.currentTimeMillis()); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); clManager.ensureUpToDate(false); final Change change1 = clManager.getChange(vf1); final Change change2 = clManager.getChange(vf2); Assert.assertNotNull(change1); Assert.assertNotNull(change2); Assert.assertNotNull(change1.getBeforeRevision()); Assert.assertNotNull(change2.getBeforeRevision()); Assert.assertNotNull(change1.getAfterRevision()); Assert.assertNotNull(change2.getAfterRevision()); }
public void perform( @NotNull Project project, com.assembla.git.GitVcs mksVcs, @NotNull List<VcsException> exceptions, @NotNull VirtualFile[] affectedFiles) throws VcsException { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { FileDocumentManager.getInstance().saveAllDocuments(); } }); if (!ProjectLevelVcsManager.getInstance(project) .checkAllFilesAreUnder(com.assembla.git.GitVcs.getInstance(project), affectedFiles)) return; final Map<VirtualFile, List<VirtualFile>> roots = com.assembla.git.GitUtil.sortFilesByVcsRoot(project, affectedFiles); for (VirtualFile root : roots.keySet()) { com.assembla.git.commands.GitCommand command = new com.assembla.git.commands.GitCommand( project, com.assembla.git.GitVcsSettings.getInstance(project), root); command.delete(roots.get(root)); } VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project); for (VirtualFile file : affectedFiles) { mgr.fileDirty(file); file.refresh(true, true); } }
public SvnVcs( final Project project, MessageBus bus, SvnConfiguration svnConfiguration, final SvnLoadedBrachesStorage storage) { super(project, VCS_NAME); myLoadedBranchesStorage = storage; LOG.debug("ct"); myRootsToWorkingCopies = new RootsToWorkingCopies(this); myConfiguration = svnConfiguration; myAuthNotifier = new SvnAuthenticationNotifier(this); dumpFileStatus(FileStatus.ADDED); dumpFileStatus(FileStatus.DELETED); dumpFileStatus(FileStatus.MERGE); dumpFileStatus(FileStatus.MODIFIED); dumpFileStatus(FileStatus.NOT_CHANGED); dumpFileStatus(FileStatus.UNKNOWN); dumpFileStatus(SvnFileStatus.REPLACED); dumpFileStatus(SvnFileStatus.EXTERNAL); dumpFileStatus(SvnFileStatus.OBSTRUCTED); final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); myAddConfirmation = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, this); myDeleteConfirmation = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, this); myCheckoutOptions = vcsManager.getStandardOption(VcsConfiguration.StandardOption.CHECKOUT, this); if (myProject.isDefault()) { myChangeListListener = null; myEntriesFileListener = null; } else { myEntriesFileListener = new SvnEntriesFileListener(project); upgradeIfNeeded(bus); myChangeListListener = new SvnChangelistListener(myProject, this); myVcsListener = new VcsListener() { @Override public void directoryMappingChanged() { invokeRefreshSvnRoots(true); } }; } myFrameStateListener = project.isDefault() ? null : new MyFrameStateListener( ChangeListManager.getInstance(project), VcsDirtyScopeManager.getInstance(project)); myWorkingCopiesContent = new WorkingCopiesContent(this); // remove used some time before old notification group ids correctNotificationIds(); myChecker = new SvnExecutableChecker(myProject); }
@CalledInAwt public static void refreshPassedFilesAndMoveToChangelist( @NotNull final Project project, final Collection<FilePath> directlyAffected, final Collection<VirtualFile> indirectlyAffected, final Consumer<Collection<FilePath>> targetChangelistMover) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); for (FilePath filePath : directlyAffected) { lfs.refreshAndFindFileByIoFile(filePath.getIOFile()); } if (project.isDisposed()) return; final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (!directlyAffected.isEmpty() && targetChangelistMover != null) { changeListManager.invokeAfterUpdate( new Runnable() { @Override public void run() { targetChangelistMover.consume(directlyAffected); } }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list"), new Consumer<VcsDirtyScopeManager>() { @Override public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) { markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected); } }, null); } else { markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected); } }
@Test public void testAddListBySvn() throws Exception { enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); final VirtualFile file = createFileInCommand("a.txt", "old content"); final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); final String targetName = "target"; // not parralel, just test of correct detection runSvn("changelist", targetName, file.getPath()); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); checkFilesAreInList(new VirtualFile[] {file}, targetName, changeListManager); }
private LineStatusTracker( @NotNull final Document document, @NotNull final Document vcsDocument, @NotNull final Project project, @NotNull final VirtualFile virtualFile, @NotNull final Mode mode) { myDocument = document; myVcsDocument = vcsDocument; myProject = project; myVirtualFile = virtualFile; myApplication = ApplicationManager.getApplication(); myFileEditorManager = FileEditorManager.getInstance(myProject); myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); myMode = mode; myRanges = new ArrayList<Range>(); }
@Before public void setUp() throws Exception { System.setProperty("svnkit.wc.17", "false"); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { try { final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); myTempDirFixture = fixtureFactory.createTempDirTestFixture(); myTempDirFixture.setUp(); final File svnRoot = new File(myTempDirFixture.getTempDirPath(), "svnroot"); svnRoot.mkdir(); File pluginRoot = new File(PluginPathManager.getPluginHomePath("svn4idea")); if (!pluginRoot.isDirectory()) { // try standalone mode Class aClass = SvnTestCase.class; String rootPath = PathManager.getResourceRoot( aClass, "/" + aClass.getName().replace('.', '/') + ".class"); pluginRoot = new File(rootPath).getParentFile().getParentFile().getParentFile(); } myClientBinaryPath = new File(pluginRoot, "testData/svn/bin"); ZipUtil.extract(new File(pluginRoot, "testData/svn/newrepo.zip"), svnRoot, null); myWcRoot = new File(myTempDirFixture.getTempDirPath(), "wcroot"); myWcRoot.mkdir(); myRepoUrl = "file:///" + FileUtil.toSystemIndependentName(svnRoot.getPath()); initProject(myWcRoot); activateVCS(SvnVcs17.VCS_NAME); verify(runSvn("co", myRepoUrl, ".")); myGate = new MockChangeListManagerGate(ChangeListManager.getInstance(myProject)); myRefreshCopiesStub = new AtomicSectionsAware() { @Override public void enter() {} @Override public void exit() {} @Override public boolean shouldExitAsap() { return false; } @Override public void checkShouldExit() throws ProcessCanceledException {} }; final SvnVcs17 vcs = SvnVcs17.getInstance(myProject); ((StartupManagerImpl) StartupManager.getInstance(myProject)) .runPostStartupActivities(); // vcs.postStartup(); ((SvnFileUrlMappingImpl17) vcs.getSvnFileUrlMapping()).realRefresh(); } catch (Exception e) { throw new RuntimeException(e); } } }); // there should be kind-a waiting for after change list manager finds all changes and runs inner // refresh of copies in the above method ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); }
@Override public void run(final ContinuationContext context) { if (myTheirsBinaryChanges.isEmpty()) return; final Application application = ApplicationManager.getApplication(); final List<FilePath> dirtyPaths = new ArrayList<FilePath>(); for (final Change change : myTheirsBinaryChanges) { try { application.runWriteAction( new ThrowableComputable<Void, VcsException>() { @Override public Void compute() throws VcsException { try { if (change.getAfterRevision() == null) { final FilePath path = change.getBeforeRevision().getFile(); dirtyPaths.add(path); final VirtualFile file = LocalFileSystem.getInstance() .refreshAndFindFileByIoFile(path.getIOFile()); if (file == null) { context.handleException( new VcsException("Can not delete file: " + file.getPath(), true), false); return null; } file.delete(TreeConflictRefreshablePanel.class); } else { final FilePath file = change.getAfterRevision().getFile(); dirtyPaths.add(file); final String parentPath = file.getParentPath().getPath(); final VirtualFile parentFile = VfsUtil.createDirectoryIfMissing(parentPath); if (parentFile == null) { context.handleException( new VcsException("Can not create directory: " + parentPath, true), false); return null; } final VirtualFile child = parentFile.createChildData( TreeConflictRefreshablePanel.class, file.getName()); if (child == null) { context.handleException( new VcsException("Can not create file: " + file.getPath(), true), false); return null; } final BinaryContentRevision revision = (BinaryContentRevision) change.getAfterRevision(); final byte[] content = revision.getBinaryContent(); // actually it was the fix for IDEA-91572 Error saving merged data: Argument 0 // for @NotNull parameter of > com/intellij/ if (content == null) { context.handleException( new VcsException( "Can not load Theirs content for file " + file.getPath()), false); return null; } child.setBinaryContent(content); } } catch (IOException e) { throw new VcsException(e); } return null; } }); } catch (VcsException e) { context.handleException(e, true); return; } } VcsDirtyScopeManager.getInstance(myVcs.getProject()).filePathsDirty(dirtyPaths, null); }
public static void markFileAsDirty(final Project project, final VirtualFile file) { VcsDirtyScopeManager.getInstance(project).fileDirty(file); }
public ResolveWorker(final boolean changesUnderProjectRoot, final Project project) { myChangesUnderProjectRoot = changesUnderProjectRoot; myProject = project; myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project); myConflictedVirtualFiles = new ArrayList<VirtualFile>(); }
/** * Preform a merge commit * * @param project a project * @param root a vcs root * @param added added files * @param removed removed files * @param messageFile a message file for commit * @param author an author * @param exceptions the list of exceptions to report * @param partialOperation * @return true if merge commit was successful */ private static boolean mergeCommit( final Project project, final VirtualFile root, final Set<FilePath> added, final Set<FilePath> removed, final File messageFile, final String author, List<VcsException> exceptions, @NotNull final PartialOperation partialOperation) { HashSet<FilePath> realAdded = new HashSet<FilePath>(); HashSet<FilePath> realRemoved = new HashSet<FilePath>(); // perform diff GitSimpleHandler diff = new GitSimpleHandler(project, root, GitCommand.DIFF); diff.setSilent(true); diff.setStdoutSuppressed(true); diff.addParameters("--diff-filter=ADMRUX", "--name-status", "HEAD"); diff.endOptions(); String output; try { output = diff.run(); } catch (VcsException ex) { exceptions.add(ex); return false; } String rootPath = root.getPath(); for (StringTokenizer lines = new StringTokenizer(output, "\n", false); lines.hasMoreTokens(); ) { String line = lines.nextToken().trim(); if (line.length() == 0) { continue; } String[] tk = line.split("\t"); switch (tk[0].charAt(0)) { case 'M': case 'A': realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[1])); break; case 'D': realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[1], false)); break; default: throw new IllegalStateException("Unexpected status: " + line); } } realAdded.removeAll(added); realRemoved.removeAll(removed); if (realAdded.size() != 0 || realRemoved.size() != 0) { final List<FilePath> files = new ArrayList<FilePath>(); files.addAll(realAdded); files.addAll(realRemoved); final Ref<Boolean> mergeAll = new Ref<Boolean>(); try { GuiUtils.runOrInvokeAndWait( new Runnable() { public void run() { String message = GitBundle.message("commit.partial.merge.message", partialOperation.getName()); SelectFilePathsDialog dialog = new SelectFilePathsDialog( project, files, message, null, "Commit All Files", CommonBundle.getCancelButtonText(), false); dialog.setTitle(GitBundle.getString("commit.partial.merge.title")); dialog.show(); mergeAll.set(dialog.isOK()); } }); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException("Unable to invoke a message box on AWT thread", ex); } if (!mergeAll.get()) { return false; } // update non-indexed files if (!updateIndex(project, root, realAdded, realRemoved, exceptions)) { return false; } for (FilePath f : realAdded) { VcsDirtyScopeManager.getInstance(project).fileDirty(f); } for (FilePath f : realRemoved) { VcsDirtyScopeManager.getInstance(project).fileDirty(f); } } // perform merge commit try { GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT); handler.setStdoutSuppressed(false); handler.addParameters("-F", messageFile.getAbsolutePath()); if (author != null) { handler.addParameters("--author=" + author); } handler.endOptions(); handler.run(); GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(root); } catch (VcsException ex) { exceptions.add(ex); return false; } return true; }
@Override protected void doVcsRefresh(final Project project, final VirtualFile file) { VcsDirtyScopeManager.getInstance(project).dirDirtyRecursively(file); }
public static void markFileAsDirty(final Project project, final FilePath path) { VcsDirtyScopeManager.getInstance(project).fileDirty(path); }
protected VirtualFile makeFile(File file) throws IOException { file.createNewFile(); VcsDirtyScopeManager.getInstance(myProject).fileDirty(myWorkingCopyDir); LocalFileSystem.getInstance().refresh(false); return VcsUtil.getVirtualFile(file); }