diff options
Diffstat (limited to 'plugins/git4idea/tests/git4idea/test')
7 files changed, 186 insertions, 107 deletions
diff --git a/plugins/git4idea/tests/git4idea/test/GitExecutor.java b/plugins/git4idea/tests/git4idea/test/GitExecutor.java index 7c561c39ebc5..f1b042ae0565 100644 --- a/plugins/git4idea/tests/git4idea/test/GitExecutor.java +++ b/plugins/git4idea/tests/git4idea/test/GitExecutor.java @@ -53,11 +53,12 @@ public class GitExecutor extends Executor { printVersionTheFirstTime(); List<String> split = splitCommandInParameters(command); split.add(0, PathHolder.GIT_EXECUTABLE); - debug("# git " + command); + File workingDir = ourCurrentDir(); + debug("[" + workingDir.getName() + "] # git " + command); for (int attempt = 0; attempt < MAX_RETRIES; attempt++) { String stdout; try { - stdout = run(split, ignoreNonZeroExitCode); + stdout = run(workingDir, split, ignoreNonZeroExitCode); if (!isIndexLockFileError(stdout)) { return stdout; } @@ -97,7 +98,7 @@ public class GitExecutor extends Executor { } public static void add(@NotNull String path) { - git("add " + path); + git("add --verbose " + path); } public static void addCommit(@NotNull String message) { diff --git a/plugins/git4idea/tests/git4idea/test/GitHttpAuthTestService.java b/plugins/git4idea/tests/git4idea/test/GitHttpAuthTestService.java index b6f25e75e307..8723ce280269 100644 --- a/plugins/git4idea/tests/git4idea/test/GitHttpAuthTestService.java +++ b/plugins/git4idea/tests/git4idea/test/GitHttpAuthTestService.java @@ -15,13 +15,11 @@ */ package git4idea.test; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import git4idea.commands.GitCommand; import git4idea.commands.GitHttpAuthService; import git4idea.commands.GitHttpAuthenticator; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author Kirill Likhodedov @@ -61,8 +59,7 @@ public class GitHttpAuthTestService extends GitHttpAuthService { @NotNull @Override - public GitHttpAuthenticator createAuthenticator(@NotNull Project project, @Nullable ModalityState state, @NotNull GitCommand command, - @NotNull String url) { + public GitHttpAuthenticator createAuthenticator(@NotNull Project project, @NotNull GitCommand command, @NotNull String url) { return myAuthenticator; } diff --git a/plugins/git4idea/tests/git4idea/test/GitMockRepositoryManager.java b/plugins/git4idea/tests/git4idea/test/GitMockRepositoryManager.java new file mode 100644 index 000000000000..21ed4da7bdfb --- /dev/null +++ b/plugins/git4idea/tests/git4idea/test/GitMockRepositoryManager.java @@ -0,0 +1,84 @@ +/* + * Copyright 2000-2013 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.repo.RepositoryManager; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vfs.VirtualFile; +import git4idea.repo.GitRepository; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Kirill Likhodedov + */ +public class GitMockRepositoryManager implements RepositoryManager<GitRepository> { + private final List<GitRepository> myRepositories = new ArrayList<GitRepository>(); + + public void add(GitRepository repository) { + myRepositories.add(repository); + } + + @Override + public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) { + for (GitRepository repository : myRepositories) { + if (repository.getRoot().equals(root)) { + return repository; + } + } + + return null; + } + + @Override + public GitRepository getRepositoryForFile(@NotNull VirtualFile file) { + throw new UnsupportedOperationException(); + } + + @Override + public GitRepository getRepositoryForFile(@NotNull FilePath file) { + throw new UnsupportedOperationException(); + } + + @NotNull + @Override + public List<GitRepository> getRepositories() { + return myRepositories; + } + + @Override + public boolean moreThanOneRoot() { + return myRepositories.size() > 1; + } + + @Override + public void updateRepository(VirtualFile root) { + throw new UnsupportedOperationException(); + } + + @Override + public void updateAllRepositories() { + throw new UnsupportedOperationException(); + } + + @Override + public void waitUntilInitialized() { + } + +} diff --git a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java index ef3f963c9c7e..c02ec553dd8f 100644 --- a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java +++ b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java @@ -19,6 +19,7 @@ import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; @@ -51,19 +52,19 @@ public abstract class GitPlatformTest extends UsefulTestCase { private static final Logger LOG = Logger.getInstance(GitPlatformTest.class); - @NotNull protected Project myProject; - @NotNull protected VirtualFile myProjectRoot; - @NotNull protected String myProjectPath; - @NotNull protected GitRepositoryManager myGitRepositoryManager; - @NotNull protected GitVcsSettings myGitSettings; - @NotNull protected GitPlatformFacade myPlatformFacade; - @NotNull protected Git myGit; - @NotNull protected GitVcs myVcs; + protected Project myProject; + protected VirtualFile myProjectRoot; + protected String myProjectPath; + protected GitRepositoryManager myGitRepositoryManager; + protected GitVcsSettings myGitSettings; + protected GitPlatformFacade myPlatformFacade; + protected Git myGit; + protected GitVcs myVcs; - @NotNull protected TestDialogManager myDialogManager; - @NotNull protected TestVcsNotifier myVcsNotifier; + protected TestDialogManager myDialogManager; + protected TestVcsNotifier myVcsNotifier; - @NotNull private IdeaProjectTestFixture myProjectFixture; + private IdeaProjectTestFixture myProjectFixture; private String myTestStartedIndicator; @SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors", "UnusedDeclaration"}) @@ -86,35 +87,41 @@ public abstract class GitPlatformTest extends UsefulTestCase { throw e; } - myProject = myProjectFixture.getProject(); - myProjectRoot = myProject.getBaseDir(); - myProjectPath = myProjectRoot.getPath(); - - myGitSettings = GitVcsSettings.getInstance(myProject); - myGitSettings.getAppSettings().setPathToGit(GitExecutor.PathHolder.GIT_EXECUTABLE); - - myDialogManager = (TestDialogManager)ServiceManager.getService(DialogManager.class); - myVcsNotifier = (TestVcsNotifier)ServiceManager.getService(myProject, VcsNotifier.class); - - myGitRepositoryManager = GitUtil.getRepositoryManager(myProject); - myPlatformFacade = ServiceManager.getService(myProject, GitPlatformFacade.class); - myGit = ServiceManager.getService(myProject, Git.class); - myVcs = ObjectUtils.assertNotNull(GitVcs.getInstance(myProject)); - myVcs.doActivate(); - - GitTestUtil.assumeSupportedGitVersion(myVcs); - initChangeListManager(); - addSilently(); - removeSilently(); + try { + myProject = myProjectFixture.getProject(); + myProjectRoot = myProject.getBaseDir(); + myProjectPath = myProjectRoot.getPath(); + + myGitSettings = GitVcsSettings.getInstance(myProject); + myGitSettings.getAppSettings().setPathToGit(GitExecutor.PathHolder.GIT_EXECUTABLE); + + myDialogManager = (TestDialogManager)ServiceManager.getService(DialogManager.class); + myVcsNotifier = (TestVcsNotifier)ServiceManager.getService(myProject, VcsNotifier.class); + + myGitRepositoryManager = GitUtil.getRepositoryManager(myProject); + myPlatformFacade = ServiceManager.getService(myProject, GitPlatformFacade.class); + myGit = ServiceManager.getService(myProject, Git.class); + myVcs = ObjectUtils.assertNotNull(GitVcs.getInstance(myProject)); + myVcs.doActivate(); + + GitTestUtil.assumeSupportedGitVersion(myVcs); + initChangeListManager(); + addSilently(); + removeSilently(); + } + catch (Exception e) { + tearDown(); + throw e; + } } @Override @NotNull public String getTestName(boolean lowercaseFirstLetter) { String name = super.getTestName(lowercaseFirstLetter); - name = name.trim().replace(' ', '_'); - if (name.length() > 50) { - name = name.substring(0, 50); + name = StringUtil.shortenTextWithEllipsis(name.trim().replace(" ", "_"), 12, 6, "_"); + if (name.startsWith("_")) { + name = name.substring(1); } return name; } @@ -127,16 +134,25 @@ public abstract class GitPlatformTest extends UsefulTestCase { @Override protected void tearDown() throws Exception { try { - myDialogManager.cleanup(); - myVcsNotifier.cleanup(); - myProjectFixture.tearDown(); - - String tempTestIndicator = myTestStartedIndicator; - clearFields(this); - myTestStartedIndicator = tempTestIndicator; + if (myDialogManager != null) { + myDialogManager.cleanup(); + } + if (myVcsNotifier != null) { + myVcsNotifier.cleanup(); + } + if (myProjectFixture != null) { + myProjectFixture.tearDown(); + } } finally { - super.tearDown(); + try { + String tempTestIndicator = myTestStartedIndicator; + clearFields(this); + myTestStartedIndicator = tempTestIndicator; + } + finally { + super.tearDown(); + } } } diff --git a/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy b/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy index 77ecf0bc9e20..1fe574ad863d 100644 --- a/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy @@ -38,14 +38,17 @@ class GitScenarios { /** * Create a branch with a commit and return back to master. */ - static def branchWithCommit(GitRepository repository, String name, String file = "branch_file.txt", String content = "branch content") { + static def branchWithCommit(GitRepository repository, String name, String file = "branch_file.txt", String content = "branch content", + boolean returnToMaster = true) { cd repository git("checkout -b $name") touch(file, content) git("add $file") git("commit -m branch_content") - git("checkout master") + if (returnToMaster) { + git("checkout master") + } } /** diff --git a/plugins/git4idea/tests/git4idea/test/GitTestRepositoryManager.java b/plugins/git4idea/tests/git4idea/test/GitTestRepositoryManager.java index 52bf562280fe..b02e952926c2 100644 --- a/plugins/git4idea/tests/git4idea/test/GitTestRepositoryManager.java +++ b/plugins/git4idea/tests/git4idea/test/GitTestRepositoryManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,70 +15,46 @@ */ package git4idea.test; -import com.intellij.dvcs.repo.RepositoryManager; -import com.intellij.openapi.vcs.FilePath; +import com.intellij.dvcs.repo.RepoStateException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vfs.VirtualFile; +import git4idea.GitPlatformFacade; import git4idea.repo.GitRepository; +import git4idea.repo.GitRepositoryImpl; +import git4idea.repo.GitRepositoryManager; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; +public class GitTestRepositoryManager extends GitRepositoryManager { -/** - * @author Kirill Likhodedov - */ -public class GitTestRepositoryManager implements RepositoryManager<GitRepository> { - private final List<GitRepository> myRepositories = new ArrayList<GitRepository>(); + @NotNull private final Project myProject; + @NotNull private final GitPlatformFacade myFacade; - public void add(GitRepository repository) { - myRepositories.add(repository); - } - - @Override - public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) { - for (GitRepository repository : myRepositories) { - if (repository.getRoot().equals(root)) { - return repository; - } - } - - return null; - } - - @Override - public GitRepository getRepositoryForFile(@NotNull VirtualFile file) { - throw new UnsupportedOperationException(); - } - - @Override - public GitRepository getRepositoryForFile(@NotNull FilePath file) { - throw new UnsupportedOperationException(); + public GitTestRepositoryManager(@NotNull Project project, + @NotNull GitPlatformFacade platformFacade, + @NotNull ProjectLevelVcsManager vcsManager) { + super(project, platformFacade, vcsManager); + myProject = project; + myFacade = platformFacade; } @NotNull @Override - public List<GitRepository> getRepositories() { - return myRepositories; - } - - @Override - public boolean moreThanOneRoot() { - return myRepositories.size() > 1; - } - - @Override - public void updateRepository(VirtualFile root) { - throw new UnsupportedOperationException(); - } - - @Override - public void updateAllRepositories() { - throw new UnsupportedOperationException(); - } - - @Override - public void waitUntilInitialized() { + protected GitRepository createRepository(@NotNull VirtualFile root) { + return new GitRepositoryImpl(root, myFacade, myProject, this, false) { + @Override + public void update() { + try { + super.update(); + } + catch (RepoStateException e) { + if (!Disposer.isDisposed(this)) { // project dir will simply be removed during dispose + throw e; + } + } + } + }; } } diff --git a/plugins/git4idea/tests/git4idea/test/GitTestUtil.java b/plugins/git4idea/tests/git4idea/test/GitTestUtil.java index 842b1b1a2bae..3525ad18f0fd 100644 --- a/plugins/git4idea/tests/git4idea/test/GitTestUtil.java +++ b/plugins/git4idea/tests/git4idea/test/GitTestUtil.java @@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitUtil; import git4idea.GitVcs; +import git4idea.config.GitVersion; import git4idea.repo.GitRepository; import org.jetbrains.annotations.NotNull; import org.jetbrains.ide.BuiltInServerManagerImpl; @@ -111,6 +112,7 @@ public class GitTestUtil { } public static void assumeSupportedGitVersion(@NotNull GitVcs vcs) { - assumeTrue(vcs.getVersion().isSupported()); + GitVersion version = vcs.getVersion(); + assumeTrue("Unsupported Git version: " + version, version.isSupported()); } } |