use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitCherryPicker method getInfo.
@Override
public String getInfo(@NotNull VcsLog log, @NotNull Map<VirtualFile, List<Hash>> commits) {
int commitsNum = commits.values().size();
for (VirtualFile root : commits.keySet()) {
// all these roots already related to this cherry-picker
GitRepository repository = ObjectUtils.assertNotNull(myRepositoryManager.getRepositoryForRoot(root));
for (Hash commit : commits.get(root)) {
GitLocalBranch currentBranch = repository.getCurrentBranch();
Collection<String> containingBranches = log.getContainingBranches(commit, root);
if (currentBranch != null && containingBranches != null && containingBranches.contains(currentBranch.getName())) {
// already in the current branch
return String.format("The current branch already contains %s the selected %s", commitsNum > 1 ? "one of" : "", pluralize("commit", commitsNum));
}
}
}
return null;
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRefManager method groupForTable.
@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean compact, boolean showTagNames) {
List<VcsRef> sortedReferences = ContainerUtil.sorted(references, myLabelsComparator);
MultiMap<VcsRefType, VcsRef> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType);
List<RefGroup> result = ContainerUtil.newArrayList();
if (groupedRefs.isEmpty())
return result;
VcsRef head = null;
Map.Entry<VcsRefType, Collection<VcsRef>> firstGroup = ObjectUtils.notNull(ContainerUtil.getFirstItem(groupedRefs.entrySet()));
if (firstGroup.getKey().equals(HEAD)) {
head = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(firstGroup.getValue()));
groupedRefs.remove(HEAD, head);
}
GitRepository repository = getRepository(references);
if (repository != null) {
result.addAll(getTrackedRefs(groupedRefs, repository));
}
result.forEach(refGroup -> {
groupedRefs.remove(LOCAL_BRANCH, refGroup.getRefs().get(0));
groupedRefs.remove(REMOTE_BRANCH, refGroup.getRefs().get(1));
});
SimpleRefGroup.buildGroups(groupedRefs, compact, showTagNames, result);
if (head != null) {
if (repository != null && !repository.isOnBranch()) {
result.add(0, new SimpleRefGroup("!", Collections.singletonList(head)));
} else {
if (!result.isEmpty()) {
RefGroup first = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(result));
first.getRefs().add(0, head);
} else {
result.add(0, new SimpleRefGroup("", Collections.singletonList(head)));
}
}
}
return result;
}
use of git4idea.repo.GitRepository 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 git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitResetOperation method execute.
public void execute() {
saveAllDocuments();
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
Map<GitRepository, GitCommandResult> results = ContainerUtil.newHashMap();
try {
for (Map.Entry<GitRepository, Hash> entry : myCommits.entrySet()) {
GitRepository repository = entry.getKey();
VirtualFile root = repository.getRoot();
String target = entry.getValue().asString();
GitLocalChangesWouldBeOverwrittenDetector detector = new GitLocalChangesWouldBeOverwrittenDetector(root, RESET);
GitCommandResult result = myGit.reset(repository, myMode, target, detector);
if (!result.success() && detector.wasMessageDetected()) {
GitCommandResult smartResult = proposeSmartReset(detector, repository, target);
if (smartResult != null) {
result = smartResult;
}
}
results.put(repository, result);
repository.update();
VfsUtil.markDirtyAndRefresh(false, true, false, root);
VcsDirtyScopeManager.getInstance(myProject).dirDirtyRecursively(root);
}
} finally {
token.finish();
}
notifyResult(results);
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitResetOperation method notifyResult.
private void notifyResult(@NotNull Map<GitRepository, GitCommandResult> results) {
Map<GitRepository, GitCommandResult> successes = ContainerUtil.newHashMap();
Map<GitRepository, GitCommandResult> errors = ContainerUtil.newHashMap();
for (Map.Entry<GitRepository, GitCommandResult> entry : results.entrySet()) {
GitCommandResult result = entry.getValue();
GitRepository repository = entry.getKey();
if (result.success()) {
successes.put(repository, result);
} else {
errors.put(repository, result);
}
}
if (errors.isEmpty()) {
myNotifier.notifySuccess("", "Reset successful");
} else if (!successes.isEmpty()) {
myNotifier.notifyImportantWarning("Reset partially failed", "Reset was successful for " + joinRepos(successes.keySet()) + "<br/>but failed for " + joinRepos(errors.keySet()) + ": <br/>" + formErrorReport(errors));
} else {
myNotifier.notifyError("Reset Failed", formErrorReport(errors));
}
}
Aggregations