mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] Tests: remove unused MockGit, GitFastTest and GitLightRepository. Make GitIntegrationEnablerTest be GitLightTest.
This commit is contained in:
@@ -21,7 +21,6 @@ import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,12 +33,16 @@ import java.util.List;
|
||||
*/
|
||||
public class MockProjectRootManager extends ProjectRootManager {
|
||||
|
||||
Collection<VirtualFile> myContentRoots = new ArrayList<VirtualFile>();
|
||||
List<VirtualFile> myContentRoots = new ArrayList<VirtualFile>();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getContentRoots() {
|
||||
return ArrayUtil.toObjectArray(VirtualFile.class, myContentRoots);
|
||||
VirtualFile[] roots = new VirtualFile[myContentRoots.size()];
|
||||
for (int i = 0; i < myContentRoots.size(); i++) {
|
||||
roots[i] = myContentRoots.get(i);
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.test;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.VfsTestUtil;
|
||||
import com.intellij.testFramework.vcs.AbstractVcsTestCase;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import git4idea.GitPlatformFacade;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
* @deprecated Use {@link GitExecutor}
|
||||
*/
|
||||
@Deprecated
|
||||
public class GitExec {
|
||||
|
||||
public static void refresh(@NotNull GitRepository repository) {
|
||||
repository.getRoot().refresh(false, true);
|
||||
}
|
||||
|
||||
public static GitRepository init(@NotNull Project project, @NotNull VirtualFile root) throws IOException {
|
||||
new GitTestRunEnv(new File(root.getPath())).run("init");
|
||||
root.refresh(false, true);
|
||||
return GitRepositoryImpl.getLightInstance(root, project, ServiceManager.getService(project, GitPlatformFacade.class), project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null in case of bare repository, because GitRepository instance for a bare repository can't be created.
|
||||
*/
|
||||
@Nullable
|
||||
public static GitRepository clone(@NotNull Project project, @NotNull String sourcePath, @NotNull String destinationPath, boolean bare)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
String[] args = bare ? new String[]{"--bare", sourcePath, destinationPath} : new String[]{sourcePath, destinationPath};
|
||||
new GitTestRunEnv(new File(sourcePath)).run("clone", args);
|
||||
VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(destinationPath));
|
||||
assert root != null;
|
||||
root.refresh(false, true);
|
||||
return bare ? null : GitRepositoryImpl.getLightInstance(root, project,
|
||||
ServiceManager.getService(project, GitPlatformFacade.class), project);
|
||||
}
|
||||
|
||||
public static String push(@NotNull GitRepository repository, String... args) throws IOException {
|
||||
return run(repository, "push", args);
|
||||
}
|
||||
|
||||
public static String remoteAdd(@NotNull GitRepository repository, String... args) throws IOException {
|
||||
return run(repository, "remote", ArrayUtil.mergeArrays(new String[]{"add"}, args));
|
||||
}
|
||||
|
||||
public static void create(@NotNull GitRepository repository, @NotNull String filePath) {
|
||||
create(repository, filePath, "content");
|
||||
}
|
||||
|
||||
public static void create(final GitRepository repository, final String filePath, @NotNull final String content) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
VfsTestUtil.createFile(repository.getRoot(), filePath, content);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void edit(final GitRepository repository, String filePath, final String newContent) {
|
||||
final VirtualFile file = repository.getRoot().findFileByRelativePath(filePath);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
AbstractVcsTestCase.editFileInCommand(repository.getProject(), file, newContent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String read(final @NotNull GitRepository repository, @NotNull String filePath) throws IOException {
|
||||
final VirtualFile file = repository.getRoot().findFileByRelativePath(filePath);
|
||||
assert file != null;
|
||||
return new String(file.contentsToByteArray());
|
||||
}
|
||||
|
||||
public static void add(@NotNull GitRepository repository, @NotNull String filePath) throws IOException {
|
||||
run(repository, "add", filePath);
|
||||
}
|
||||
|
||||
public static void add(@NotNull GitRepository repository) throws IOException {
|
||||
run(repository, "add", ".");
|
||||
}
|
||||
|
||||
public static void commit(@NotNull GitRepository repository) throws IOException {
|
||||
run(repository, "commit", "-m", "message");
|
||||
}
|
||||
|
||||
public static void addCommit(@NotNull GitRepository repository, @NotNull String filePath) throws IOException {
|
||||
add(repository, filePath);
|
||||
commit(repository);
|
||||
}
|
||||
|
||||
public static void addCommit(@NotNull GitRepository repository) throws IOException {
|
||||
add(repository);
|
||||
commit(repository);
|
||||
}
|
||||
|
||||
public static void createAddCommit(@NotNull GitRepository repository, @NotNull String filePath) throws IOException {
|
||||
create(repository, filePath);
|
||||
addCommit(repository, filePath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String branch(@NotNull GitRepository repository, String... params) throws IOException {
|
||||
return run(repository, "branch", params);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String currentBranch(@NotNull GitRepository repository) throws IOException {
|
||||
String[] branches = branch(repository).split("\n");
|
||||
for (String branch : branches) {
|
||||
if (branch.trim().startsWith("*")) {
|
||||
return branch.trim().substring(1).trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void checkout(@NotNull GitRepository repository, String... params) throws IOException {
|
||||
run(repository, "checkout", params);
|
||||
}
|
||||
|
||||
public static void merge(@NotNull GitRepository repository, @NotNull String branch) throws IOException {
|
||||
run(repository, "merge", branch);
|
||||
}
|
||||
|
||||
public static String tip(@NotNull GitRepository repository) throws IOException {
|
||||
return run(repository, "rev-list", "-1", "HEAD");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String run(@NotNull GitRepository repository, @NotNull String command, String... params) throws IOException {
|
||||
return new GitTestRunEnv(new File(repository.getRoot().getPath())).run(command, params);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.test
|
||||
|
||||
import com.intellij.dvcs.test.MockVcsHelper
|
||||
import com.intellij.dvcs.test.MockVirtualFile
|
||||
import com.intellij.notification.Notification
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
|
||||
import static junit.framework.Assert.assertEquals
|
||||
import static junit.framework.Assert.assertNotNull
|
||||
/**
|
||||
*
|
||||
* @author Kirill Likhodedov
|
||||
* @deprecated Use {@link GitLightTest}
|
||||
*/
|
||||
@Deprecated
|
||||
class GitFastTest {
|
||||
|
||||
public static final String TEST_NOTIFICATION_GROUP = "Test"
|
||||
|
||||
Project myProject
|
||||
GitTestPlatformFacade myPlatformFacade
|
||||
GitTestRepositoryManager myRepositoryManager
|
||||
MockGit myGit
|
||||
String myProjectDir
|
||||
TestDialogManager myDialogManager
|
||||
MockVcsHelper myVcsHelper
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
myProjectDir = FileUtil.createTempDirectory("git", null)
|
||||
|
||||
myProject = [
|
||||
getBaseDir: { new MockVirtualFile(myProjectDir) }
|
||||
] as Project
|
||||
|
||||
myPlatformFacade = new GitTestPlatformFacade()
|
||||
myGit = new MockGit()
|
||||
myDialogManager = myPlatformFacade.getDialogManager()
|
||||
myRepositoryManager = (GitTestRepositoryManager) myPlatformFacade.getRepositoryManager(myProject)
|
||||
myVcsHelper = (MockVcsHelper) myPlatformFacade.getVcsHelper(myProject)
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() {
|
||||
FileUtil.delete(new File(myProjectDir))
|
||||
}
|
||||
|
||||
void assertNotificationShown(Notification expected) {
|
||||
if (expected) {
|
||||
Notification actualNotification = (myPlatformFacade.getNotificator(myProject) as TestNotificator).lastNotification
|
||||
assertNotNull "No notification was shown", actualNotification
|
||||
assertEquals "Notification has wrong title", expected.title, actualNotification.title
|
||||
assertEquals "Notification has wrong type", expected.type, actualNotification.type
|
||||
assertEquals "Notification has wrong content", adjustTestContent(expected.content), actualNotification.content
|
||||
}
|
||||
}
|
||||
|
||||
// we allow more spaces and line breaks in tests to make them more readable.
|
||||
// After all, notifications display html, so all line breaks and extra spaces are ignored.
|
||||
String adjustTestContent(String s) {
|
||||
StringBuilder res = new StringBuilder()
|
||||
s.split("\n").each { res.append it.trim() }
|
||||
res.toString()
|
||||
}
|
||||
|
||||
void assertNotificationShown(String title, String message, NotificationType type) {
|
||||
assertNotificationShown(new Notification(TEST_NOTIFICATION_GROUP, title, message, type))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.test;
|
||||
|
||||
import com.intellij.dvcs.test.MockVirtualFile;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.branch.GitBranchesCollection;
|
||||
import git4idea.repo.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import sun.security.provider.SHA;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Simulates Git repository.
|
||||
* Made for unit tests, not to spawn a Git process.
|
||||
* Stores information about commits and branches in memory.
|
||||
*
|
||||
* @author Kirill Likhodedov
|
||||
*
|
||||
* @deprecated Use the standard GitRepository instance returned from {@link GitRepositoryImpl.getLightInstance()}
|
||||
*/
|
||||
@Deprecated
|
||||
public class GitLightRepository implements GitRepository {
|
||||
|
||||
public static class Commit {
|
||||
@Nullable private Commit myParent;
|
||||
@NotNull private String myHash;
|
||||
@NotNull private String myCommitMessage;
|
||||
|
||||
public Commit(String hash, String message, Commit parent) {
|
||||
myHash = hash;
|
||||
myCommitMessage = message;
|
||||
myParent = parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getCommitMessage() {
|
||||
return myCommitMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Commit getParent() {
|
||||
return myParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Commit commit = (Commit)o;
|
||||
|
||||
if (!myCommitMessage.equals(commit.myCommitMessage)) return false;
|
||||
if (!myHash.equals(commit.myHash)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myHash.hashCode();
|
||||
result = 31 * result + myCommitMessage.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Branch {
|
||||
@NotNull private String myName;
|
||||
@Nullable private Commit myCommit;
|
||||
|
||||
public Branch(String name, Commit commit) {
|
||||
myName = name;
|
||||
myCommit = commit;
|
||||
}
|
||||
}
|
||||
|
||||
private Branch myHead;
|
||||
|
||||
public GitLightRepository() {
|
||||
myHead = new Branch("master", null);
|
||||
}
|
||||
|
||||
public Commit commit(String commitMessage) {
|
||||
Commit parent = myHead.myCommit;
|
||||
String hash = new SHA().toString();
|
||||
Commit commit = new Commit(hash, commitMessage, parent);
|
||||
myHead.myCommit = commit;
|
||||
return commit;
|
||||
}
|
||||
|
||||
public Commit cherryPick(String commitMessage) {
|
||||
return commit(commitMessage);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Commit getHead() {
|
||||
return myHead.myCommit;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile getRoot() {
|
||||
return new MockVirtualFile(FileUtil.getTempDirectory());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile getGitDir() {
|
||||
return new MockVirtualFile(getRoot().getPath() + "/.git");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableUrl() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GitUntrackedFilesHolder getUntrackedFilesHolder() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public State getState() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentRevision() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GitLocalBranch getCurrentBranch() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GitBranchesCollection getBranches() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<GitRemote> getRemotes() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<GitBranchTrackInfo> getBranchTrackInfos() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMergeInProgress() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRebaseInProgress() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnBranch() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFresh() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLogString() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class GitTestImpl implements Git {
|
||||
@NotNull
|
||||
@Override
|
||||
public GitCommandResult init(@NotNull Project project, @NotNull VirtualFile root, @NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException();
|
||||
return execute(root.getPath(), "init", listeners);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -279,7 +279,11 @@ public class GitTestImpl implements Git {
|
||||
}
|
||||
|
||||
private static GitCommandResult execute(GitRepository repository, String operation, GitLineHandlerListener... listeners) {
|
||||
cd(repository);
|
||||
return execute(repository.getRoot().getPath(), operation, listeners);
|
||||
}
|
||||
|
||||
private static GitCommandResult execute(String workingDir, String operation, GitLineHandlerListener... listeners) {
|
||||
cd(workingDir);
|
||||
String out = git(operation);
|
||||
feedOutput(out, listeners);
|
||||
return commandResult(out);
|
||||
|
||||
@@ -1,320 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.test
|
||||
|
||||
import com.intellij.execution.process.ProcessOutputTypes
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.containers.hash.HashMap
|
||||
import git4idea.commands.Git
|
||||
import git4idea.commands.GitCommandResult
|
||||
import git4idea.commands.GitLineHandlerListener
|
||||
import git4idea.history.browser.GitCommit
|
||||
import git4idea.push.GitPushSpec
|
||||
import git4idea.repo.GitRepository
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
|
||||
import static MockGit.OperationName.CHERRY_PICK
|
||||
import static MockGit.OperationName.GET_UNMERGED_FILES
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Kirill Likhodedov
|
||||
*
|
||||
* @deprecated Use {@link GitTestImpl} - prefer fair Git to the simulation.
|
||||
*/
|
||||
@Deprecated
|
||||
class MockGit implements Git {
|
||||
|
||||
public static final GitCommandResult FAKE_SUCCESS_RESULT = new GitCommandResult(true, 0, Collections.emptyList(), Collections.emptyList())
|
||||
private final Map<OperationName, Queue<OperationExecutor>> myExecutors = new HashMap<OperationName, Queue<OperationExecutor>>()
|
||||
|
||||
public enum OperationName {
|
||||
CHERRY_PICK,
|
||||
GET_UNMERGED_FILES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register executors for specific operations. These are put into queues, i.e. once operation is called, the executor is popped out of the
|
||||
* queue. If the queue is empty or certain operation, then it is executed as by default.
|
||||
*/
|
||||
void registerOperationExecutors(OperationExecutor... executors) {
|
||||
for (OperationExecutor executor : executors) {
|
||||
OperationName name = executor.getName()
|
||||
Queue<OperationExecutor> exs = myExecutors.get(name)
|
||||
if (exs == null) {
|
||||
exs = new ArrayDeque<OperationExecutor>()
|
||||
myExecutors.put(name, exs)
|
||||
}
|
||||
exs.add(executor)
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult init(@NotNull Project project, @NotNull VirtualFile root, @NotNull GitLineHandlerListener... listeners) {
|
||||
new File(root.path, ".git").mkdir()
|
||||
FAKE_SUCCESS_RESULT
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
Set<VirtualFile> untrackedFiles(@NotNull Project project, @NotNull VirtualFile root, Collection<VirtualFile> files) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
Collection<VirtualFile> untrackedFilesNoChunk(@NotNull Project project, @NotNull VirtualFile root, List<String> relativePaths) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult clone(@NotNull Project project, @NotNull File parentDirectory, @NotNull String url, @NotNull String clonedDirectoryName) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult config(@NotNull GitRepository repository, String... params) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
GitCommandResult diff(GitRepository repository, List<String> parameters, String range) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult merge(@NotNull GitRepository repository, @NotNull String branchToMerge, @Nullable List<String> additionalParams,
|
||||
@NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult checkout(@NotNull GitRepository repository, @NotNull String reference, String newBranch, boolean force, @NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult checkoutNewBranch(@NotNull GitRepository repository, @NotNull String branchName, GitLineHandlerListener listener) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult createNewTag(@NotNull GitRepository repository, @NotNull String tagName, GitLineHandlerListener listener, @NotNull String reference) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult branchDelete(@NotNull GitRepository repository, @NotNull String branchName, boolean force, @NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult branchContains(@NotNull GitRepository repository, @NotNull String commit) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult branchCreate(@NotNull GitRepository repository, @NotNull String branchName) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult resetHard(@NotNull GitRepository repository, @NotNull String revision) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult resetMerge(@NotNull GitRepository repository, String revision) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult tip(@NotNull GitRepository repository, @NotNull String branchName) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult push(@NotNull GitRepository repository, @NotNull String remote, @NotNull String spec, @NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult push(@NotNull GitRepository repository, @NotNull GitPushSpec pushSpec, @NotNull GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult show(@NotNull GitRepository repository, @NotNull String... params) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult cherryPick(@NotNull GitRepository repository, @NotNull String hash, boolean autoCommit, @NotNull GitLineHandlerListener... listeners) {
|
||||
GitCommandResult result = callExecutor(CHERRY_PICK)
|
||||
if (result != null) {
|
||||
produceOutput(result.getOutputAsJoinedString(), listeners)
|
||||
return result;
|
||||
}
|
||||
((GitLightRepository)repository).cherryPick("cherry-pick from $hash")
|
||||
return FAKE_SUCCESS_RESULT
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult getUnmergedFiles(@NotNull GitRepository repository) {
|
||||
GitCommandResult result = callExecutor(GET_UNMERGED_FILES)
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
return FAKE_SUCCESS_RESULT
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult checkAttr(@NotNull GitRepository repository, @NotNull Collection<String> attributes, @NotNull Collection<VirtualFile> files) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult stashSave(@NotNull GitRepository repository, @NotNull String message) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
GitCommandResult stashPop(@NotNull GitRepository repository, GitLineHandlerListener... listeners) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
List<GitCommit> history(GitRepository repository, String range) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
private void produceOutput(String output, GitLineHandlerListener... listeners) {
|
||||
for (String line : output.split("\n")) { // for simplicity all output goes to OUTPUT, no ERROR
|
||||
listeners.each { it.onLineAvailable(line, ProcessOutputTypes.STDOUT) }
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GitCommandResult callExecutor(OperationName operationName) {
|
||||
Queue<OperationExecutor> cherryPickExecutors = myExecutors.get(operationName)
|
||||
if (cherryPickExecutors != null && !cherryPickExecutors.isEmpty()) {
|
||||
OperationExecutor executor = cherryPickExecutors.poll()
|
||||
return executor.execute()
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class SimpleErrorOperationExecutor implements OperationExecutor {
|
||||
|
||||
String myOutput
|
||||
MockGit.OperationName myOperationName
|
||||
|
||||
SimpleErrorOperationExecutor(MockGit.OperationName operationName, String output) {
|
||||
myOutput = output;
|
||||
myOperationName = operationName
|
||||
}
|
||||
|
||||
@Override
|
||||
GitCommandResult execute() {
|
||||
return result(myOutput, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
MockGit.OperationName getName() {
|
||||
return myOperationName
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleSuccessOperationExecutor implements OperationExecutor {
|
||||
|
||||
String myOutput
|
||||
MockGit.OperationName myOperationName
|
||||
|
||||
SimpleSuccessOperationExecutor(MockGit.OperationName operationName, String output) {
|
||||
myOutput = output;
|
||||
myOperationName = operationName
|
||||
}
|
||||
|
||||
@Override
|
||||
GitCommandResult execute() {
|
||||
return result(myOutput, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
MockGit.OperationName getName() {
|
||||
return myOperationName
|
||||
}
|
||||
}
|
||||
|
||||
private static GitCommandResult result(String output, boolean success) {
|
||||
new GitCommandResult(success, success ? 0 : 127, Collections.emptyList(), Collections.singletonList(output))
|
||||
}
|
||||
|
||||
public static class SuccessfulCherryPickExecutor implements OperationExecutor {
|
||||
|
||||
GitRepository myRepository
|
||||
GitCommit myOriginalCommit
|
||||
|
||||
SuccessfulCherryPickExecutor(GitRepository repository, GitCommit originalCommit) {
|
||||
myRepository = repository;
|
||||
myOriginalCommit = originalCommit
|
||||
}
|
||||
|
||||
@Override
|
||||
GitCommandResult execute() {
|
||||
((GitLightRepository)myRepository).cherryPick(commitMessageForCherryPick(myOriginalCommit))
|
||||
return FAKE_SUCCESS_RESULT
|
||||
}
|
||||
|
||||
@Override
|
||||
OperationName getName() {
|
||||
return CHERRY_PICK
|
||||
}
|
||||
}
|
||||
|
||||
static String commitMessageForCherryPick(GitCommit commit) {
|
||||
"$commit.subject\n\n(cherry-picked from ${commit.shortHash.getString()})"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface OperationExecutor {
|
||||
GitCommandResult execute();
|
||||
MockGit.OperationName getName();
|
||||
}
|
||||
@@ -15,22 +15,37 @@
|
||||
*/
|
||||
package git4idea.roots
|
||||
|
||||
import com.intellij.dvcs.test.MockVirtualFile
|
||||
import com.intellij.notification.Notification
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import git4idea.test.GitFastTest
|
||||
import com.intellij.dvcs.test.MockVirtualFile
|
||||
import git4idea.test.GitLightTest
|
||||
import git4idea.test.TestNotificator
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import static git4idea.test.GitGTestUtil.toAbsolute
|
||||
import static junit.framework.Assert.assertEquals
|
||||
import static junit.framework.Assert.assertTrue
|
||||
import static junit.framework.Assert.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
class GitIntegrationEnablerTest extends GitFastTest {
|
||||
class GitIntegrationEnablerTest extends GitLightTest {
|
||||
|
||||
public static final String TEST_NOTIFICATION_GROUP = "Test"
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
void "1 root for the whole project, then just add VCS root"() {
|
||||
@@ -43,7 +58,7 @@ class GitIntegrationEnablerTest extends GitFastTest {
|
||||
doTest given( [], false ),
|
||||
expect( git_init: ["."],
|
||||
vcs_roots: ["."],
|
||||
notification("Created Git repository in $myProjectDir"))
|
||||
notification("Created Git repository in $myProjectRoot"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +108,7 @@ class GitIntegrationEnablerTest extends GitFastTest {
|
||||
|
||||
void assertGitInit(Collection<String> roots) {
|
||||
roots.each {
|
||||
assertTrue ".git" in new File(myProjectDir + "/" + it).list()
|
||||
assertTrue ".git" in new File(myProjectRoot + "/" + it).list()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +132,29 @@ class GitIntegrationEnablerTest extends GitFastTest {
|
||||
}
|
||||
|
||||
String path(String relativePath) {
|
||||
new File(myProjectDir + "/" + relativePath).canonicalPath
|
||||
new File(myProjectRoot + "/" + relativePath).canonicalPath
|
||||
}
|
||||
|
||||
void assertNotificationShown(Notification expected) {
|
||||
if (expected) {
|
||||
Notification actualNotification = (myPlatformFacade.getNotificator(myProject) as TestNotificator).lastNotification
|
||||
assertNotNull "No notification was shown", actualNotification
|
||||
assertEquals "Notification has wrong title", expected.title, actualNotification.title
|
||||
assertEquals "Notification has wrong type", expected.type, actualNotification.type
|
||||
assertEquals "Notification has wrong content", adjustTestContent(expected.content), actualNotification.content
|
||||
}
|
||||
}
|
||||
|
||||
// we allow more spaces and line breaks in tests to make them more readable.
|
||||
// After all, notifications display html, so all line breaks and extra spaces are ignored.
|
||||
String adjustTestContent(String s) {
|
||||
StringBuilder res = new StringBuilder()
|
||||
s.split("\n").each { res.append it.trim() }
|
||||
res.toString()
|
||||
}
|
||||
|
||||
void assertNotificationShown(String title, String message, NotificationType type) {
|
||||
assertNotificationShown(new Notification(TEST_NOTIFICATION_GROUP, title, message, type))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user