mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-135966 support the case when there are no local branches
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user