[git] IDEA-134412 fresh repository should be on branch

This commit is contained in:
Kirill Likhodedov
2015-01-15 19:10:27 +03:00
parent 685f27b2ce
commit f0ea5015b4
2 changed files with 31 additions and 5 deletions
@@ -80,11 +80,22 @@ class GitRepositoryReader {
@NotNull
GitBranchState readState(@NotNull Collection<GitRemote> remotes) {
Pair<Set<GitLocalBranch>, Set<GitRemoteBranch>> branches = readBranches(remotes);
Set<GitLocalBranch> localBranches = branches.first;
HeadInfo headInfo = readHead();
Repository.State state = readRepositoryState(headInfo);
GitLocalBranch currentBranch = findCurrentBranch(headInfo, state, branches.first);
String currentRevision = getCurrentRevision(headInfo, currentBranch);
return new GitBranchState(currentRevision, currentBranch, state, branches.first, branches.second);
GitLocalBranch currentBranch;
String currentRevision;
if (localBranches.isEmpty() && headInfo.content != null) {
currentBranch = new GitLocalBranch(headInfo.content, GitBranch.DUMMY_HASH);
currentRevision = null;
}
else {
currentBranch = findCurrentBranch(headInfo, state, localBranches);
currentRevision = getCurrentRevision(headInfo, currentBranch);
}
return new GitBranchState(currentRevision, currentBranch, state, localBranches, branches.second);
}
@Nullable
@@ -18,6 +18,7 @@ package git4idea.repo;
import com.intellij.dvcs.repo.Repository;
import com.intellij.openapi.util.Condition;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitLocalBranch;
import git4idea.GitRemoteBranch;
import git4idea.test.GitSingleRepoTest;
import org.jetbrains.annotations.NotNull;
@@ -39,7 +40,8 @@ import static git4idea.test.GitTestUtil.makeCommit;
public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
// inspired by IDEA-93806
public void test_rebase_with_conflicts_while_being_on_detached_HEAD() {
public void test_rebase_with_conflicts_while_being_on_detached_HEAD() throws IOException {
makeCommit("file.txt");
conflict(myRepo, "feature");
commit(myRepo);
commit(myRepo);
@@ -52,7 +54,8 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
}
// inspired by IDEA-124052
public void test_remote_reference_without_remote() {
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");
@@ -68,6 +71,7 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
// inspired by IDEA-134286
public void test_detached_HEAD() throws IOException {
makeCommit("file.txt");
makeCommit("file.txt");
git("checkout HEAD^");
GitBranchState state = readState();
@@ -84,4 +88,15 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
return reader.readState(remotes);
}
// 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());
}
@Override
protected boolean makeInitialCommit() {
return false;
}
}