use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitConflictResolver method unmergedFiles.
/**
* Parse changes from lines
*
*
* @param root the git root
* @return a set of unmerged files
* @throws com.intellij.openapi.vcs.VcsException if the input format does not matches expected format
*/
private List<VirtualFile> unmergedFiles(final VirtualFile root) throws VcsException {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository not found for root " + root);
return Collections.emptyList();
}
GitCommandResult result = myGit.getUnmergedFiles(repository);
if (!result.success()) {
throw new VcsException(result.getErrorOutputAsJoinedString());
}
String output = StringUtil.join(result.getOutput(), "\n");
HashSet<String> unmergedPaths = ContainerUtil.newHashSet();
for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
if (s.isEol()) {
s.nextLine();
continue;
}
s.boundedToken('\t');
String relative = s.line();
unmergedPaths.add(GitUtil.unescapePath(relative));
}
if (unmergedPaths.size() == 0) {
return Collections.emptyList();
} else {
List<File> files = ContainerUtil.map(unmergedPaths, new Function<String, File>() {
@Override
public File fun(String path) {
return new File(root.getPath(), path);
}
});
return sortVirtualFilesByPresentation(findVirtualFilesWithRefresh(files));
}
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitRollbackEnvironment method registerFile.
/**
* Register file in the map under appropriate root
*
* @param files a map to use
* @param file a file to register
* @param exceptions the list of exceptions to update
*/
private static void registerFile(Map<VirtualFile, List<FilePath>> files, FilePath file, List<VcsException> exceptions) {
final VirtualFile root;
try {
root = GitUtil.getGitRoot(file);
} catch (VcsException e) {
exceptions.add(e);
return;
}
List<FilePath> paths = files.get(root);
if (paths == null) {
paths = new ArrayList<>();
files.put(root, paths);
}
paths.add(file);
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitRollbackEnvironment method rollbackChanges.
public void rollbackChanges(@NotNull List<Change> changes, final List<VcsException> exceptions, @NotNull final RollbackProgressListener listener) {
HashMap<VirtualFile, List<FilePath>> toUnindex = new HashMap<>();
HashMap<VirtualFile, List<FilePath>> toUnversion = new HashMap<>();
HashMap<VirtualFile, List<FilePath>> toRevert = new HashMap<>();
List<FilePath> toDelete = new ArrayList<>();
listener.determinate();
// collect changes to revert
for (Change c : changes) {
switch(c.getType()) {
case NEW:
// note that this the only change that could happen
// for HEAD-less working directories.
registerFile(toUnversion, c.getAfterRevision().getFile(), exceptions);
break;
case MOVED:
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
registerFile(toUnindex, c.getAfterRevision().getFile(), exceptions);
toDelete.add(c.getAfterRevision().getFile());
break;
case MODIFICATION:
// note that changes are also removed from index, if they got into index somehow
registerFile(toUnindex, c.getBeforeRevision().getFile(), exceptions);
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
break;
case DELETED:
registerFile(toRevert, c.getBeforeRevision().getFile(), exceptions);
break;
}
}
// unindex files
for (Map.Entry<VirtualFile, List<FilePath>> entry : toUnindex.entrySet()) {
listener.accept(entry.getValue());
try {
unindex(entry.getKey(), entry.getValue(), false);
} catch (VcsException e) {
exceptions.add(e);
}
}
// unversion files
for (Map.Entry<VirtualFile, List<FilePath>> entry : toUnversion.entrySet()) {
listener.accept(entry.getValue());
try {
unindex(entry.getKey(), entry.getValue(), true);
} catch (VcsException e) {
exceptions.add(e);
}
}
// delete files
for (FilePath file : toDelete) {
listener.accept(file);
try {
final File ioFile = file.getIOFile();
if (ioFile.exists()) {
if (!ioFile.delete()) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Unable to delete file: " + file));
}
}
} catch (Exception e) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Unable to delete file: " + file, e));
}
}
// revert files from HEAD
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
for (Map.Entry<VirtualFile, List<FilePath>> entry : toRevert.entrySet()) {
listener.accept(entry.getValue());
try {
revert(entry.getKey(), entry.getValue());
} catch (VcsException e) {
exceptions.add(e);
}
}
} finally {
token.finish();
}
LocalFileSystem lfs = LocalFileSystem.getInstance();
HashSet<File> filesToRefresh = new HashSet<>();
for (Change c : changes) {
ContentRevision before = c.getBeforeRevision();
if (before != null) {
filesToRefresh.add(new File(before.getFile().getPath()));
}
ContentRevision after = c.getAfterRevision();
if (after != null) {
filesToRefresh.add(new File(after.getFile().getPath()));
}
}
lfs.refreshIoFiles(filesToRefresh);
for (GitRepository repo : GitUtil.getRepositoryManager(myProject).getRepositories()) {
repo.update();
}
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitOutgoingCommitsProvider method getOutgoingCommits.
@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec, boolean initial) {
GitLocalBranch branch = pushSpec.getSource().getBranch();
String source = branch.equals(repository.getCurrentBranch()) ? HEAD : branch.getFullName();
GitPushTarget target = pushSpec.getTarget();
String destination = target.getBranch().getFullName();
try {
List<GitCommit> commits;
if (!target.isNewBranchCreated()) {
commits = GitHistoryUtils.history(myProject, repository.getRoot(), destination + ".." + source);
} else {
commits = GitHistoryUtils.history(myProject, repository.getRoot(), source, "--not", "--remotes=" + target.getBranch().getRemote().getName(), "--max-count=" + 1000);
}
return new OutgoingResult(commits, Collections.<VcsError>emptyList());
} catch (VcsException e) {
return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), Collections.singletonList(new VcsError(GitUtil.cleanupErrorPrefixes(e.getMessage()))));
}
}
use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.
the class GitPushOperation method collectUpdatedFiles.
private void collectUpdatedFiles(@NotNull UpdatedFiles updatedFiles, @NotNull GitRepository repository, @NotNull String preUpdatePosition) {
MergeChangeCollector collector = new MergeChangeCollector(myProject, repository.getRoot(), new GitRevisionNumber(preUpdatePosition));
ArrayList<VcsException> exceptions = new ArrayList<>();
collector.collect(updatedFiles, exceptions);
for (VcsException exception : exceptions) {
LOG.info(exception);
}
}
Aggregations