aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scm
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <77498856+lukasz-jarocki-sonarsource@users.noreply.github.com>2021-02-26 09:29:39 +0100
committersonartech <sonartech@sonarsource.com>2021-02-26 20:07:39 +0000
commit9cb17b6dbce261af578b7c5fe430fa340d4ff1ad (patch)
treedecb117810be86812b2849f8adb388de5a97919d /sonar-scanner-engine/src/test/java/org/sonar/scm
parent26ca7559fab8b6a0379468a0a5b5f7d83c1baaa9 (diff)
downloadsonarqube-9cb17b6dbce261af578b7c5fe430fa340d4ff1ad.tar.gz
sonarqube-9cb17b6dbce261af578b7c5fe430fa340d4ff1ad.zip
Revert SONAR-14478, SONAR-14462, SONAR-14461
* Revert "SONAR-14478 - Main Branch Documentation" This reverts commit 59eae7cf3f2e611e162a4e0122ae5846b10a45b1. * Revert "SONAR-14462 Do not display the branch name until the main branch is analyzed for the first time" This reverts commit 20f7319c06affdae62d39d1bad002f16504465a2. * Revert "SONAR-14461 main branch detection" This reverts commit c04baa1e8e3b492953d66a6bc4111c01f3ee3069. * Revert "SONAR-14461 Remove hardcoded usage of 'master'" This reverts commit 32eefaf2d36af375af280cc3ba664fd71e0f6afd. * Revert "SONAR-14461 save the default main branch when needed" This reverts commit 879a4be2afc570b2248fb4d639f42f913215805b.
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scm')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java130
1 files changed, 0 insertions, 130 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
index 4a9a6121aa9..4efb0ddcb33 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
@@ -39,19 +39,15 @@ import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;
-
-import org.eclipse.jgit.api.CreateBranchCommand;
import org.eclipse.jgit.api.DiffCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
-import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.junit.Before;
import org.junit.Rule;
@@ -736,132 +732,6 @@ public class GitScmProviderTest {
assertThat(provider.revisionId(projectDir)).isNull();
}
- @Test
- public void getMainBranch_givenRepoWithOneBranchCalledMain_returnMainBranchCalledMain() throws Exception {
- //given
- worktree = temp.newFolder().toPath();
- Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
- repo.create();
- git = new Git(repo);
-
- addBranchInConfig("Main");
-
- Path projectDir = worktree.resolve("project");
- Files.createDirectory(projectDir);
-
- GitScmProvider provider = newGitScmProvider();
-
- //when
- String mainBranch = provider.getMainBranch(projectDir);
-
- //then
- assertThat(mainBranch).isEqualTo("Main");
- }
-
- @Test
- public void getMainBranch_givenRepoWithTwoBranches_returnFirstBranch() throws Exception {
- //given
- worktree = temp.newFolder().toPath();
- Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
- repo.create();
- git = new Git(repo);
-
- addBranchInConfig("First");
- addBranchInConfig("Second");
-
- Path projectDir = worktree.resolve("project");
- Files.createDirectory(projectDir);
-
- GitScmProvider provider = newGitScmProvider();
-
- //when
- String mainBranch = provider.getMainBranch(projectDir);
-
- //then
- assertThat(mainBranch).isEqualTo("First");
- }
-
- @Test
- public void getMainBranch_givenNoBranches_dontThrowException() throws Exception {
- //given
- worktree = temp.newFolder().toPath();
- Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
- repo.create();
- git = new Git(repo);
-
- Path projectDir = worktree.resolve("project");
- Files.createDirectory(projectDir);
-
- GitScmProvider provider = newGitScmProvider();
-
- //when
- String mainBranch = provider.getMainBranch(projectDir);
-
- //then no exception
- assertThat(mainBranch).isNullOrEmpty();
- }
-
- @Test
- public void getMainBranch_givenRepositoryNotFoundExceptionWhenBuildingRepo_returnNull() throws Exception {
- //given
-
- worktree = temp.newFolder().toPath();
- Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
- repo.create();
- git = new Git(repo);
- repo.getObjectDatabase().close(); //This is here to force RepositoryBuilder to throw subclass of IOException
-
- Path projectDir = worktree.resolve("project");
- Files.createDirectory(projectDir);
-
- GitScmProvider provider = newGitScmProvider();
-
- //when
- String mainBranch = provider.getMainBranch(projectDir);
-
- //then no exception
- assertThat(mainBranch).isNullOrEmpty();
- }
-
- @Test
- public void getMainBranch_givenIOExceptionWhenBuildingRepo_returnNull() throws Exception {
- //given
-
- worktree = temp.newFolder().toPath();
- Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
- repo.create();
- git = new Git(repo);
-
- Path projectDir = worktree.resolve("project");
- Files.createDirectory(projectDir);
-
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
- @Override
- Repository buildRepo(Path basedir) throws IOException {
- throw new IOException();
- }
- };
-
- //when
- String mainBranch = provider.getMainBranch(projectDir);
-
- //then no exception
- assertThat(mainBranch).isNullOrEmpty();
- }
-
- /**
- * Normally after cloning the repository we would have at least one
- * branch it git config. This method adds these branches without
- * cloning any repository (because unit tests ought to be fast)
- */
- private void addBranchInConfig(String ... branches) throws IOException {
- for(String branch : branches) {
- git.getRepository().getConfig().setStringList("branch", branch, "remote", Arrays.asList("origin"));
- git.getRepository().getConfig().setStringList("branch", branch, "merge", Arrays.asList("refs/head/" + branch));
- }
- git.getRepository().getConfig().save();
- }
-
private String randomizedContent(String prefix, int numLines) {
StringBuilder sb = new StringBuilder();
for (int line = 0; line < numLines; line++) {