mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git tests: convert to kotlin
This commit is contained in:
@@ -13,123 +13,102 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.repo;
|
||||
package git4idea.repo
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.GitRemoteBranch;
|
||||
import git4idea.branch.GitBranchUtil;
|
||||
import git4idea.test.GitSingleRepoTest;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static git4idea.test.GitExecutor.git;
|
||||
import static git4idea.test.GitExecutor.last;
|
||||
import static git4idea.test.GitScenarios.commit;
|
||||
import static git4idea.test.GitScenarios.conflict;
|
||||
import static git4idea.test.GitTestUtil.makeCommit;
|
||||
import com.intellij.dvcs.repo.Repository.State
|
||||
import git4idea.branch.GitBranchUtil
|
||||
import git4idea.test.GitExecutor.git
|
||||
import git4idea.test.GitExecutor.last
|
||||
import git4idea.test.GitScenarios.commit
|
||||
import git4idea.test.GitScenarios.conflict
|
||||
import git4idea.test.GitSingleRepoTest
|
||||
import git4idea.test.GitTestUtil.makeCommit
|
||||
|
||||
/**
|
||||
* {@link GitRepositoryReaderTest} reads information from the pre-created .git directory from a real project.
|
||||
* [GitRepositoryReaderTest] reads information from the pre-created .git directory from a real project.
|
||||
* This one, on the other hand, operates on a live Git repository, putting it to various situations and checking the results.
|
||||
*/
|
||||
public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
|
||||
class GitRepositoryReaderNewTest : GitSingleRepoTest() {
|
||||
|
||||
// inspired by IDEA-93806
|
||||
public void test_rebase_with_conflicts_while_being_on_detached_HEAD() throws IOException {
|
||||
makeCommit("file.txt");
|
||||
conflict(myRepo, "feature");
|
||||
commit(myRepo);
|
||||
commit(myRepo);
|
||||
git("checkout HEAD^");
|
||||
git("rebase feature", true);
|
||||
|
||||
GitBranchState state = readState();
|
||||
assertNull("Current branch can't be identified for this case", state.getCurrentBranch());
|
||||
assertEquals("State value is incorrect", Repository.State.REBASING, state.getState());
|
||||
override fun makeInitialCommit(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
// inspired by IDEA-124052
|
||||
public void test_remote_reference_without_remote() throws IOException {
|
||||
makeCommit("file.txt");
|
||||
final String INVALID_REMOTE = "invalid-remote";
|
||||
final String INVALID_REMOTE_BRANCH = "master";
|
||||
git("update-ref refs/remotes/" + INVALID_REMOTE + "/" + INVALID_REMOTE_BRANCH + " HEAD");
|
||||
fun `test rebase with conflicts while being on detached HEAD`() {
|
||||
makeCommit("file.txt")
|
||||
conflict(myRepo, "feature")
|
||||
commit(myRepo)
|
||||
commit(myRepo)
|
||||
git("checkout HEAD^")
|
||||
git("rebase feature", true)
|
||||
|
||||
Collection<GitRemoteBranch> remoteBranches = readState().getRemoteBranches().keySet();
|
||||
assertTrue("Remote branch not found", ContainerUtil.exists(remoteBranches, new Condition<GitRemoteBranch>() {
|
||||
@Override
|
||||
public boolean value(GitRemoteBranch branch) {
|
||||
return branch.getNameForLocalOperations().equals(INVALID_REMOTE + "/" + INVALID_REMOTE_BRANCH);
|
||||
}
|
||||
}));
|
||||
val state = readState()
|
||||
assertNull("Current branch can't be identified for this case", state.currentBranch)
|
||||
assertEquals("State value is incorrect", State.REBASING, state.state)
|
||||
}
|
||||
|
||||
// inspired by IDEA-134286
|
||||
public void test_detached_HEAD() throws IOException {
|
||||
String head = getToDetachedHead();
|
||||
GitBranchState state = readState();
|
||||
assertEquals("Detached HEAD is not detected", GitRepository.State.DETACHED, state.getState());
|
||||
assertEquals("Detached HEAD hash is incorrect", head, state.getCurrentRevision());
|
||||
// IDEA-124052
|
||||
fun `test remote reference without remote`() {
|
||||
makeCommit("file.txt")
|
||||
val INVALID_REMOTE = "invalid-remote"
|
||||
val INVALID_REMOTE_BRANCH = "master"
|
||||
git("update-ref refs/remotes/$INVALID_REMOTE/$INVALID_REMOTE_BRANCH HEAD")
|
||||
|
||||
val remoteBranches = readState().remoteBranches.keys
|
||||
assertTrue("Remote branch not found", remoteBranches.any { it.nameForLocalOperations == "$INVALID_REMOTE/$INVALID_REMOTE_BRANCH" })
|
||||
}
|
||||
|
||||
// inspired by IDEA-135966
|
||||
public void test_no_local_branches() throws IOException {
|
||||
String head = getToDetachedHead();
|
||||
git("branch -D master");
|
||||
GitBranchState state = readState();
|
||||
assertEquals("Detached HEAD is not detected", GitRepository.State.DETACHED, state.getState());
|
||||
assertEquals("Detached HEAD hash is incorrect", head, state.getCurrentRevision());
|
||||
assertTrue("There should be no local branches", state.getLocalBranches().isEmpty());
|
||||
// IDEA-134286
|
||||
fun `test detached HEAD`() {
|
||||
val head = moveToDetachedHead()
|
||||
val state = readState()
|
||||
assertEquals("Detached HEAD is not detected", State.DETACHED, state.state)
|
||||
assertEquals("Detached HEAD hash is incorrect", head, state.currentRevision)
|
||||
}
|
||||
|
||||
public void test_tracking_remote_with_complex_name() throws IOException {
|
||||
makeCommit("file.txt");
|
||||
git("remote add my/remote http://my.remote.git");
|
||||
git("update-ref refs/remotes/my/remote/master HEAD");
|
||||
git("config branch.master.remote my/remote");
|
||||
git("config branch.master.merge refs/heads/master");
|
||||
myRepo.update();
|
||||
|
||||
|
||||
GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(myRepo, ObjectUtils.assertNotNull(myRepo.getCurrentBranch()));
|
||||
assertNotNull(trackInfo);
|
||||
GitRemote remote = trackInfo.getRemote();
|
||||
assertEquals("my/remote", remote.getName());
|
||||
assertEquals("http://my.remote.git", remote.getFirstUrl());
|
||||
// IDEA-135966
|
||||
fun `test no local branches`() {
|
||||
val head = moveToDetachedHead()
|
||||
git("branch -D master")
|
||||
val state = readState()
|
||||
assertEquals("Detached HEAD is not detected", State.DETACHED, state.state)
|
||||
assertEquals("Detached HEAD hash is incorrect", head, state.currentRevision)
|
||||
assertTrue("There should be no local branches", state.localBranches.isEmpty())
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getToDetachedHead() throws IOException {
|
||||
makeCommit("file.txt");
|
||||
makeCommit("file.txt");
|
||||
git("checkout HEAD^");
|
||||
return last();
|
||||
fun `test tracking remote with complex name`() {
|
||||
makeCommit("file.txt")
|
||||
git("remote add my/remote http://my.remote.git")
|
||||
git("update-ref refs/remotes/my/remote/master HEAD")
|
||||
git("config branch.master.remote my/remote")
|
||||
git("config branch.master.merge refs/heads/master")
|
||||
myRepo.update()
|
||||
|
||||
val trackInfo = GitBranchUtil.getTrackInfoForBranch(myRepo, myRepo.currentBranch!!)!!
|
||||
val remote = trackInfo.remote
|
||||
assertEquals("my/remote", remote.name)
|
||||
assertEquals("http://my.remote.git", remote.firstUrl)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private GitBranchState readState() {
|
||||
GitRepositoryFiles gitFiles = myRepo.getRepositoryFiles();
|
||||
GitConfig config = GitConfig.read(myPlatformFacade, gitFiles.getConfigFile());
|
||||
GitRepositoryReader reader = new GitRepositoryReader(gitFiles);
|
||||
Collection<GitRemote> remotes = config.parseRemotes();
|
||||
return reader.readState(remotes);
|
||||
// IDEA-134412
|
||||
fun `test fresh repository is on branch`() {
|
||||
val currentBranch = readState().currentBranch
|
||||
assertNotNull("Current branch shouldn't be null in a fresh repository", currentBranch)
|
||||
assertEquals("Fresh repository should be on master", "master", currentBranch!!.name)
|
||||
}
|
||||
|
||||
// inspired by IDEA-134412
|
||||
public void test_fresh_repository_is_on_branch() {
|
||||
GitLocalBranch currentBranch = readState().getCurrentBranch();
|
||||
assertNotNull("Current branch shouldn't be null in a fresh repository", currentBranch);
|
||||
assertEquals("Fresh repository should be on master", "master", currentBranch.getName());
|
||||
private fun moveToDetachedHead(): String {
|
||||
makeCommit("file.txt")
|
||||
makeCommit("file.txt")
|
||||
git("checkout HEAD^")
|
||||
return last()
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean makeInitialCommit() {
|
||||
return false;
|
||||
private fun readState(): GitBranchState {
|
||||
val gitFiles = myRepo.repositoryFiles
|
||||
val config = GitConfig.read(myPlatformFacade, gitFiles.configFile)
|
||||
val reader = GitRepositoryReader(gitFiles)
|
||||
val remotes = config.parseRemotes()
|
||||
return reader.readState(remotes)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user