use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitStashChangesSaver method loadRoot.
/**
* Returns true if the root was loaded with conflict.
* False is returned in all other cases: in the case of success and in case of some other error.
*/
private boolean loadRoot(final VirtualFile root) {
LOG.info("loadRoot " + root);
myProgressIndicator.setText(GitHandlerUtil.formatOperationName("Unstashing changes to", root));
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository is null for root " + root);
return false;
}
GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT_ON_UNSTASH);
GitCommandResult result = myGit.stashPop(repository, conflictDetector);
VfsUtil.markDirtyAndRefresh(false, true, false, root);
if (result.success()) {
return false;
} else if (conflictDetector.hasHappened()) {
return true;
} else {
LOG.info("unstash failed " + result.getErrorOutputAsJoinedString());
GitUIUtil.notifyImportantError(myProject, "Couldn't unstash", "<br/>" + result.getErrorOutputAsHtmlString());
return false;
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitStashChangesSaver method save.
@Override
protected void save(@NotNull Collection<VirtualFile> rootsToSave) throws VcsException {
LOG.info("saving " + rootsToSave);
for (VirtualFile root : rootsToSave) {
final String message = GitHandlerUtil.formatOperationName("Stashing changes from", root);
LOG.info(message);
final String oldProgressTitle = myProgressIndicator.getText();
myProgressIndicator.setText(message);
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository is null for root " + root);
} else {
GitCommandResult result = myGit.stashSave(repository, myStashMessage);
if (result.success() && somethingWasStashed(result)) {
myStashedRoots.add(root);
} else {
String error = "stash " + repository.getRoot() + ": " + result.getErrorOutputAsJoinedString();
if (!result.success()) {
throw new VcsException(error);
} else {
LOG.warn(error);
}
}
}
myProgressIndicator.setText(oldProgressTitle);
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitNewResetDialog method prepareDescription.
@NotNull
private static String prepareDescription(@NotNull Project project, @NotNull Map<GitRepository, VcsFullCommitDetails> commits) {
if (commits.size() == 1 && !isMultiRepo(project)) {
Map.Entry<GitRepository, VcsFullCommitDetails> entry = commits.entrySet().iterator().next();
return String.format("%s -> %s", getSourceText(entry.getKey()), getTargetText(entry.getValue()));
}
StringBuilder desc = new StringBuilder("");
for (Map.Entry<GitRepository, VcsFullCommitDetails> entry : commits.entrySet()) {
GitRepository repository = entry.getKey();
VcsFullCommitDetails commit = entry.getValue();
desc.append(String.format("%s in %s -> %s<br/>", getSourceText(repository), getShortRepositoryName(repository), getTargetText(commit)));
}
return desc.toString();
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRollbackEnvironment method unindex.
/**
* Remove file paths from index (git remove --cached).
*
* @param root a git root
* @param files files to remove from index.
* @param toUnversioned passed true if the file will be unversioned after unindexing, i.e. it was added before the revert operation.
* @throws VcsException if there is a problem with running git
*/
private void unindex(final VirtualFile root, final List<FilePath> files, boolean toUnversioned) throws VcsException {
GitFileUtils.delete(myProject, root, files, "--cached", "-f");
if (toUnversioned) {
final GitRepository repo = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
final GitUntrackedFilesHolder untrackedFilesHolder = (repo == null ? null : repo.getUntrackedFilesHolder());
for (FilePath path : files) {
final VirtualFile vf = VcsUtil.getVirtualFile(path.getIOFile());
if (untrackedFilesHolder != null && vf != null) {
untrackedFilesHolder.add(vf);
}
}
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitPusher method rememberTargets.
private void rememberTargets(@NotNull Map<GitRepository, PushSpec<GitPushSource, GitPushTarget>> pushSpecs) {
for (Map.Entry<GitRepository, PushSpec<GitPushSource, GitPushTarget>> entry : pushSpecs.entrySet()) {
GitRepository repository = entry.getKey();
GitPushSource source = entry.getValue().getSource();
GitPushTarget target = entry.getValue().getTarget();
GitPushTarget defaultTarget = myPushSupport.getDefaultTarget(repository);
if (defaultTarget == null || !target.getBranch().equals(defaultTarget.getBranch())) {
mySettings.setPushTarget(repository, source.getBranch().getName(), target.getBranch().getRemote().getName(), target.getBranch().getNameForRemoteOperations());
}
}
}
Aggregations