[git] IDEA-135966 support the case when there are no local branches

This commit is contained in:
Kirill Likhodedov
2015-02-15 17:54:27 +03:00
parent fb2a944159
commit 2e9b39674b
2 changed files with 30 additions and 6 deletions
@@ -87,13 +87,21 @@ class GitRepositoryReader {
GitLocalBranch currentBranch;
String currentRevision;
if (localBranches.isEmpty() && headInfo.content != null) {
if (!headInfo.isBranch) {
currentBranch = null;
currentRevision = headInfo.content;
}
else if (!localBranches.isEmpty()) {
currentBranch = findCurrentBranch(headInfo, state, localBranches);
currentRevision = getCurrentRevision(headInfo, currentBranch);
}
else if (headInfo.content != null) {
currentBranch = new GitLocalBranch(headInfo.content, GitBranch.DUMMY_HASH);
currentRevision = null;
}
else {
currentBranch = findCurrentBranch(headInfo, state, localBranches);
currentRevision = getCurrentRevision(headInfo, currentBranch);
currentBranch = null;
currentRevision = null;
}
return new GitBranchState(currentRevision, currentBranch, state, localBranches, branches.second);
}
@@ -71,12 +71,28 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
// 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());
}
// 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());
}
@NotNull
private static String getToDetachedHead() throws IOException {
makeCommit("file.txt");
makeCommit("file.txt");
git("checkout HEAD^");
GitBranchState state = readState();
assertEquals("Detached HEAD is not detected", GitRepository.State.DETACHED, state.getState());
assertEquals("Detached HEAD hash is incorrect", last(), state.getCurrentRevision());
return last();
}
@NotNull