com.intellij.openapi.vcs.update.FileGroup Java Examples

The following examples show how to use com.intellij.openapi.vcs.update.FileGroup. 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: TFSUpdateEnvironmentTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(CommandUtils.class, ConflictsEnvironment.class, TfsFileUtil.class, TFVCUtil.class);
    when(mockTFSVcs.getServerContext(anyBoolean())).thenReturn(mockServerContext);
    when(mockTFSVcs.getProject()).thenReturn(mockProject);
    when(ConflictsEnvironment.getConflictsHandler()).thenReturn(mockConflictsHandler);
    when(mockUpdatedFiles.getGroupById(FileGroup.REMOVED_FROM_REPOSITORY_ID)).thenReturn(mockFileGroupRemove);
    when(mockUpdatedFiles.getGroupById(FileGroup.CREATED_ID)).thenReturn(mockFileGroupCreate);
    when(mockUpdatedFiles.getGroupById(FileGroup.UPDATED_ID)).thenReturn(mockFileGroupUpdate);
    when(TFVCUtil.filterValidTFVCPaths(eq(mockProject), anyCollectionOf(FilePath.class))).then(new Answer<Collection<String>>() {
        @Override
        public Collection<String> answer(InvocationOnMock invocation) throws Throwable {
            @SuppressWarnings("unchecked") Collection<FilePath> argument = (Collection<FilePath>) invocation.getArguments()[1];
            ArrayList<String> result = new ArrayList<String>();
            for (FilePath filePath : argument) {
                result.add(filePath.getPath());
            }
            return result;
        }
    });

    updateEnvironment = new TFSUpdateEnvironment(mockProject, mockTFSVcs);
}
 
Example #2
Source File: P4SyncUpdateEnvironment.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private void updateForResult(@Nullable FetchFilesResult res, Map<String, FileGroup> groups) {
    if (res == null) {
        return;
    }
    for (P4LocalFile file : res.getFiles()) {

        // hardRefresh and refresh are deprecated now.  We don't need to do that anymore.
        // path.hardRefresh();

        String groupId = getGroupIdFor(file);
        FileGroup group = groups.get(groupId);
        if (group != null) {
            group.add(file.getFilePath().getIOFile().getAbsolutePath(),
                    P4Vcs.getKey(), file.getHaveRevision());
        }

    }
}
 
Example #3
Source File: ChangesCacheFile.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean processUpdatedFiles(UpdatedFiles updatedFiles, Collection<CommittedChangeList> receivedChanges) throws IOException {
  boolean haveUnaccountedUpdatedFiles = false;
  openStreams();
  loadHeader();
  ReceivedChangeListTracker tracker = new ReceivedChangeListTracker();
  try {
    final List<IncomingChangeListData> incomingData = loadIncomingChangeListData();
    for(FileGroup group: updatedFiles.getTopLevelGroups()) {
      haveUnaccountedUpdatedFiles |= processGroup(group, incomingData, tracker);
    }
    if (!haveUnaccountedUpdatedFiles) {
      for(IncomingChangeListData data: incomingData) {
        saveIncoming(data, false);
      }
      writeHeader();
    }
  }
  finally {
    closeStreams();
  }
  receivedChanges.addAll(tracker.getChangeLists());
  return haveUnaccountedUpdatedFiles;
}
 
Example #4
Source File: ChangesCacheFile.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean processGroup(final FileGroup group, final List<IncomingChangeListData> incomingData,
                             final ReceivedChangeListTracker tracker) {
  boolean haveUnaccountedUpdatedFiles = false;
  final List<Pair<String,VcsRevisionNumber>> list = group.getFilesAndRevisions(myVcsManager);
  for(Pair<String, VcsRevisionNumber> pair: list) {
    final String file = pair.first;
    FilePath path = new FilePathImpl(new File(file), false);
    if (!path.isUnder(myRootPath, false) || pair.second == null) {
      continue;
    }
    if (group.getId().equals(FileGroup.REMOVED_FROM_REPOSITORY_ID)) {
      haveUnaccountedUpdatedFiles |= processDeletedFile(path, incomingData, tracker);
    }
    else {
      haveUnaccountedUpdatedFiles |= processFile(path, pair.second, incomingData, tracker);
    }
  }
  for(FileGroup childGroup: group.getChildren()) {
    haveUnaccountedUpdatedFiles |= processGroup(childGroup, incomingData, tracker);
  }
  return haveUnaccountedUpdatedFiles;
}
 
Example #5
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testResolveConflict_Happy() throws Exception {
    when(CommandUtils.resolveConflictsByPath(mockServerContext, Arrays.asList(CONFLICT_BOTH.getLocalPath()), ResolveConflictsCommand.AutoResolveType.KeepYours)).thenReturn(Arrays.asList(CONFLICT_BOTH));
    helper.resolveConflict(CONFLICT_BOTH.getLocalPath(), ((RenameConflict) CONFLICT_BOTH).getServerPath(), ResolveConflictsCommand.AutoResolveType.KeepYours, mockServerContext, mockResolveConflictsModel, true, null);

    verify(mockUpdatedFiles).getGroupById(FileGroup.MERGED_ID);
    verify(mockFileGroup).add(((RenameConflict) CONFLICT_BOTH).getServerPath(), TFSVcs.getKey(), null);
}
 
Example #6
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testAcceptTheirs() {
    helper.acceptChanges("/path/to/file_with_conflict", ResolveConflictsCommand.AutoResolveType.TakeTheirs);

    verify(mockUpdatedFiles).getGroupById(FileGroup.UPDATED_ID);
    verify(mockFileGroup).add("/path/to/file_with_conflict", TFSVcs.getKey(), null);
}
 
Example #7
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testAcceptYours() {
    helper.acceptChanges("/path/to/file_with_conflict", ResolveConflictsCommand.AutoResolveType.KeepYours);

    verify(mockUpdatedFiles).getGroupById(FileGroup.SKIPPED_ID);
    verify(mockFileGroup).add("/path/to/file_with_conflict", TFSVcs.getKey(), null);
}
 
Example #8
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testSkip() {
    helper.skip(Arrays.asList(new Conflict("/path/to/file1", Conflict.ConflictType.CONTENT), new Conflict("/path/to/file2", Conflict.ConflictType.RENAME)));

    verify(mockUpdatedFiles, times(2)).getGroupById(FileGroup.SKIPPED_ID);
    verify(mockFileGroup).add("/path/to/file1", TFSVcs.getKey(), null);
    verify(mockFileGroup).add("/path/to/file2", TFSVcs.getKey(), null);
    verifyNoMoreInteractions(mockFileGroup, mockUpdatedFiles);
}
 
Example #9
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testAcceptChange_Happy() {
    when(CommandUtils.getConflicts(any(ServerContext.class), anyString(), any(MergeResults.class))).thenReturn(Arrays.asList(CONFLICT_RENAME, CONFLICT_CONTEXT));
    when(CommandUtils.resolveConflictsByConflict(any(ServerContext.class), eq(Arrays.asList(CONFLICT_CONTEXT)), eq(ResolveConflictsCommand.AutoResolveType.TakeTheirs))).thenReturn(Arrays.asList(CONFLICT_CONTEXT));
    when(CommandUtils.resolveConflictsByConflict(any(ServerContext.class), eq(Arrays.asList(CONFLICT_RENAME)), eq(ResolveConflictsCommand.AutoResolveType.TakeTheirs))).thenReturn(Arrays.asList(CONFLICT_RENAME));
    helper.acceptChange(Arrays.asList(CONFLICT_RENAME, CONFLICT_CONTEXT), mock(ProgressIndicator.class), mockProject, ResolveConflictsCommand.AutoResolveType.TakeTheirs, mockResolveConflictsModel);

    verify(mockResolveConflictsModel, never()).addError(any(ModelValidationInfo.class));
    verify(mockUpdatedFiles, times(2)).getGroupById(FileGroup.UPDATED_ID);
    verify(mockFileGroup).add(((RenameConflict) CONFLICT_RENAME).getServerPath(), TFSVcs.getKey(), null);
    verify(mockFileGroup).add(CONFLICT_CONTEXT.getLocalPath(), TFSVcs.getKey(), null);
}
 
Example #10
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void testAcceptChange_Skipped() {
    when(CommandUtils.getConflicts(any(ServerContext.class), anyString(), any(MergeResults.class))).thenReturn(Arrays.asList(CONFLICT_RENAME));
    // return empty lit since nothing was resolved and instead skipped
    when(CommandUtils.resolveConflictsByConflict(any(ServerContext.class), eq(Arrays.asList(CONFLICT_RENAME)), eq(ResolveConflictsCommand.AutoResolveType.TakeTheirs))).thenReturn(Collections.EMPTY_LIST);
    helper.acceptChange(Arrays.asList(CONFLICT_RENAME), mock(ProgressIndicator.class), mockProject, ResolveConflictsCommand.AutoResolveType.TakeTheirs, mockResolveConflictsModel);

    verify(mockResolveConflictsModel, never()).addError(any(ModelValidationInfo.class));
    verify(mockUpdatedFiles).getGroupById(FileGroup.SKIPPED_ID);
    verify(mockFileGroup).add(CONFLICT_RENAME.getLocalPath(), TFSVcs.getKey(), null);
}
 
Example #11
Source File: P4SyncUpdateEnvironment.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private String getGroupIdFor(@NotNull final P4LocalFile file) {
    switch (file.getFileAction()) {
        case ADD:
        case ADD_EDIT:
            return FileGroup.LOCALLY_ADDED_ID;

        case REOPEN:
        case EDIT:
            return FileGroup.MODIFIED_ID;

        case MOVE_ADD_EDIT:
        case MOVE_ADD:
            return FileGroup.LOCALLY_ADDED_ID;

        case EDIT_RESOLVED:
            return FileGroup.MERGED_ID;

        case INTEGRATE:
            return FileGroup.MERGED_ID;

        case DELETE:
        case MOVE_DELETE:
            return FileGroup.LOCALLY_REMOVED_ID;

        case REVERTED:
            return FileGroup.RESTORED_ID;

        case MOVE_EDIT:
            return FileGroup.MERGED_ID;

        case NONE:
            return FileGroup.UPDATED_ID;

        case UNKNOWN:
        default:
            return FileGroup.UNKNOWN_ID;
    }
}
 
Example #12
Source File: P4SyncUpdateEnvironment.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private Map<String, FileGroup> collateByFileGroupId(final List<FileGroup> groups, Map<String, FileGroup> sorted) {
    if (sorted == null) {
        sorted = new HashMap<>();
    }

    for (FileGroup group : groups) {
        sorted.put(group.getId(), group);
        sorted = collateByFileGroupId(group.getChildren(), sorted);
    }

    return sorted;
}
 
Example #13
Source File: P4StatusUpdateEnvironment.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void fillGroups(UpdatedFiles updatedFiles) {
    updatedFiles.registerGroup(new FileGroup(
            P4Bundle.message("update.status.offline"),
            P4Bundle.message("update.status.offline"),
            false,
            OFFLINE_GROUP_ID,
            false));
}
 
Example #14
Source File: ResolveConflictHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public void acceptTheirs(final @NotNull String conflict) {
    if (updatedFiles != null) {
        //TODO create version number
        updatedFiles.getGroupById(FileGroup.UPDATED_ID).add(conflict, TFSVcs.getKey(), null);
    }
}
 
Example #15
Source File: ResolveConflictHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public void skip(final @NotNull String conflict) {
    if (updatedFiles != null) {
        // JetBrains used null for version number in this case
        updatedFiles.getGroupById(FileGroup.SKIPPED_ID).add(conflict, TFSVcs.getKey(), null);
    }
}