use of git4idea.repo.GitRepositoryManager in project intellij-community by JetBrains.
the class GitMergeAction method handleResult.
private void handleResult(GitCommandResult result, Project project, GitSimpleEventDetector mergeConflictDetector, GitLocalChangesWouldBeOverwrittenDetector localChangesDetector, GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector, GitRepository repository, GitRevisionNumber currentRev, Label beforeLabel) {
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
VirtualFile root = repository.getRoot();
if (result.success() || mergeConflictDetector.hasHappened()) {
VfsUtil.markDirtyAndRefresh(false, true, false, root);
List<VcsException> exceptions = new ArrayList<>();
GitMergeUtil.showUpdates(project, exceptions, root, currentRev, beforeLabel, getActionName(), ActionInfo.UPDATE);
repositoryManager.updateRepository(root);
showErrors(project, getActionName(), exceptions);
} else if (localChangesDetector.wasMessageDetected()) {
LocalChangesWouldBeOverwrittenHelper.showErrorNotification(project, repository.getRoot(), getActionName(), localChangesDetector.getRelativeFilePaths());
} else if (untrackedFilesDetector.wasMessageDetected()) {
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), getActionName(), null);
} else {
GitUIUtil.notifyError(project, "Git " + getActionName() + " Failed", result.getErrorOutputAsJoinedString(), true, null);
repositoryManager.updateRepository(root);
}
}
use of git4idea.repo.GitRepositoryManager in project intellij-community by JetBrains.
the class GitResetHead method perform.
/**
* {@inheritDoc}
*/
protected void perform(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
GitResetDialog d = new GitResetDialog(project, gitRoots, defaultRoot);
if (!d.showAndGet()) {
return;
}
GitLineHandler h = d.handler();
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine());
} finally {
token.finish();
}
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
manager.updateRepository(d.getGitRoot());
VfsUtil.markDirtyAndRefresh(true, true, false, d.getGitRoot());
if (!h.errors().isEmpty()) {
showErrors(project, getActionName(), h.errors());
}
}
use of git4idea.repo.GitRepositoryManager in project intellij-community by JetBrains.
the class GitUtil method getRepositoryForRootOrLogError.
@Nullable
public static GitRepository getRepositoryForRootOrLogError(@NotNull Project project, @NotNull VirtualFile root) {
GitRepositoryManager manager = getRepositoryManager(project);
GitRepository repository = manager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository is null for root " + root);
}
return repository;
}
use of git4idea.repo.GitRepositoryManager in project intellij-community by JetBrains.
the class GitUtil method getRepositoriesForFiles.
@NotNull
public static Collection<GitRepository> getRepositoriesForFiles(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
final GitRepositoryManager manager = getRepositoryManager(project);
com.google.common.base.Function<VirtualFile, GitRepository> ROOT_TO_REPO = new com.google.common.base.Function<VirtualFile, GitRepository>() {
@Override
public GitRepository apply(@Nullable VirtualFile root) {
return root != null ? manager.getRepositoryForRoot(root) : null;
}
};
return Collections2.filter(Collections2.transform(sortFilesByGitRootsIgnoringOthers(files).keySet(), ROOT_TO_REPO), Predicates.notNull());
}
use of git4idea.repo.GitRepositoryManager in project intellij-community by JetBrains.
the class GitCheckinEnvironment method commit.
public List<VcsException> commit(@NotNull List<Change> changes, @NotNull String message, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
List<VcsException> exceptions = new ArrayList<>();
Map<VirtualFile, Collection<Change>> sortedChanges = sortChangesByGitRoot(changes, exceptions);
LOG.assertTrue(!sortedChanges.isEmpty(), "Trying to commit an empty list of changes: " + changes);
for (Map.Entry<VirtualFile, Collection<Change>> entry : sortedChanges.entrySet()) {
VirtualFile root = entry.getKey();
File messageFile;
try {
messageFile = createMessageFile(root, message);
} catch (IOException ex) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Creation of commit message file failed", ex));
continue;
}
Set<FilePath> added = new HashSet<>();
Set<FilePath> removed = new HashSet<>();
final Set<Change> caseOnlyRenames = new HashSet<>();
for (Change change : entry.getValue()) {
switch(change.getType()) {
case NEW:
case MODIFICATION:
added.add(change.getAfterRevision().getFile());
break;
case DELETED:
removed.add(change.getBeforeRevision().getFile());
break;
case MOVED:
FilePath afterPath = change.getAfterRevision().getFile();
FilePath beforePath = change.getBeforeRevision().getFile();
if (!SystemInfo.isFileSystemCaseSensitive && GitUtil.isCaseOnlyChange(beforePath.getPath(), afterPath.getPath())) {
caseOnlyRenames.add(change);
} else {
added.add(afterPath);
removed.add(beforePath);
}
break;
default:
throw new IllegalStateException("Unknown change type: " + change.getType());
}
}
try {
if (!caseOnlyRenames.isEmpty()) {
List<VcsException> exs = commitWithCaseOnlyRename(myProject, root, caseOnlyRenames, added, removed, messageFile, myNextCommitAuthor);
exceptions.addAll(map(exs, GitCheckinEnvironment::cleanupExceptionText));
} else {
try {
Set<FilePath> files = new HashSet<>();
files.addAll(added);
files.addAll(removed);
commit(myProject, root, files, messageFile);
} catch (VcsException ex) {
PartialOperation partialOperation = isMergeCommit(ex);
if (partialOperation == PartialOperation.NONE) {
throw ex;
}
if (!mergeCommit(myProject, root, added, removed, messageFile, myNextCommitAuthor, exceptions, partialOperation)) {
throw ex;
}
}
}
} catch (VcsException e) {
exceptions.add(cleanupExceptionText(e));
} finally {
if (!messageFile.delete()) {
LOG.warn("Failed to remove temporary file: " + messageFile);
}
}
}
if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) {
GitRepositoryManager manager = getRepositoryManager(myProject);
Collection<GitRepository> repositories = GitUtil.getRepositoriesFromRoots(manager, sortedChanges.keySet());
final List<GitRepository> preselectedRepositories = newArrayList(repositories);
GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, GitBranchUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
}
return exceptions;
}
Aggregations