Don't read branch.lock files as branches

Since Git 2.10 (92b1551b1d407065f961ffd1d972481063a0edcc) such
lock files can be created to synchronize ref updates.

We used to read them as branches and later fail either because no hash
was available, or because the files were removed.
This commit is contained in:
Kirill Likhodedov
2017-03-02 22:58:28 +00:00
parent 3a3cbc92d6
commit 0668f251cf
2 changed files with 12 additions and 5 deletions
@@ -31,6 +31,7 @@ import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.impl.HashImpl;
import git4idea.*;
import git4idea.branch.GitBranchUtil;
import git4idea.validators.GitRefNameValidator;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -272,7 +273,7 @@ class GitRepositoryReader {
if (relativePath != null) {
String branchName = prefix + FileUtil.toSystemIndependentName(relativePath);
String hash = loadHashFromBranchFile(file);
if (hash != null) {
if (hash != null && GitRefNameValidator.getInstance().checkInput(branchName)) {
result.put(branchName, hash);
}
}
@@ -19,13 +19,11 @@ import com.intellij.dvcs.repo.Repository.State
import com.intellij.openapi.util.SystemInfo
import git4idea.GitLocalBranch
import git4idea.branch.GitBranchUtil
import git4idea.test.*
import git4idea.test.GitScenarios.commit
import git4idea.test.GitScenarios.conflict
import git4idea.test.GitSingleRepoTest
import git4idea.test.makeCommit
import git4idea.test.git
import git4idea.test.last
import org.junit.Assume.assumeTrue
import java.io.File
import kotlin.test.assertNotEquals
/**
@@ -153,6 +151,14 @@ class GitRepositoryReaderNewTest : GitSingleRepoTest() {
assertNotEquals(GitLocalBranch("UpperCase"), GitLocalBranch("uppercase"))
}
fun `test non-branch files are ignored`() {
tac("f.txt")
assertTrue(File(myRepo.repositoryFiles.refsHeadsFile, "master.lock").createNewFile())
myRepo.update()
assertSameElements(listOf("master"), myRepo.branches.localBranches.map { it.name })
}
private fun moveToDetachedHead(): String {
makeCommit("file.txt")
makeCommit("file.txt")