mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: extract method to get unmerged files
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ContentRevision;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitContentRevision;
|
||||
import git4idea.GitRevisionNumber;
|
||||
import git4idea.GitUtil;
|
||||
@@ -417,6 +418,29 @@ public class GitChangeUtils {
|
||||
return changes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<File> getUnmergedFiles(@NotNull GitRepository repository) throws VcsException {
|
||||
GitCommandResult result = Git.getInstance().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));
|
||||
}
|
||||
|
||||
VirtualFile root = repository.getRoot();
|
||||
return ContainerUtil.map(unmergedPaths, path -> new File(root.getPath(), path));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<Change> getDiffWithWorkingDir(@NotNull Project project,
|
||||
@NotNull VirtualFile root,
|
||||
|
||||
@@ -17,14 +17,12 @@ import com.intellij.openapi.vcs.VcsNotifier;
|
||||
import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
|
||||
import com.intellij.openapi.vcs.merge.MergeProvider;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.changes.GitChangeUtils;
|
||||
import git4idea.commands.Git;
|
||||
import git4idea.commands.GitCommandResult;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import git4idea.util.StringScanner;
|
||||
import org.jetbrains.annotations.CalledInBackground;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -260,48 +258,13 @@ public class GitConflictResolver {
|
||||
* @see #getUnmergedFiles(java.util.Collection
|
||||
*/
|
||||
private Collection<VirtualFile> getUnmergedFiles(@NotNull VirtualFile root) throws VcsException {
|
||||
return unmergedFiles(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, path -> new File(root.getPath(), path));
|
||||
return sortVirtualFilesByPresentation(findVirtualFilesWithRefresh(files));
|
||||
}
|
||||
List<File> files = GitChangeUtils.getUnmergedFiles(repository);
|
||||
return sortVirtualFilesByPresentation(findVirtualFilesWithRefresh(files));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user