mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-141883 don't read ignored files
This commit is contained in:
@@ -22,16 +22,16 @@ public interface StreamProvider {
|
||||
public open val enabled: Boolean
|
||||
get() = true
|
||||
|
||||
public open fun isApplicable(fileSpec: String, roamingType: RoamingType): Boolean = true
|
||||
public open fun isApplicable(fileSpec: String, roamingType: RoamingType = RoamingType.PER_USER): Boolean = true
|
||||
|
||||
/**
|
||||
* @param fileSpec
|
||||
* @param content bytes of content, size of array is not actual size of data, you must use `size`
|
||||
* @param size actual size of data
|
||||
*/
|
||||
public fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType)
|
||||
public fun write(fileSpec: String, content: ByteArray, size: Int = content.size(), roamingType: RoamingType = RoamingType.PER_USER)
|
||||
|
||||
public fun read(fileSpec: String, roamingType: RoamingType): InputStream?
|
||||
public fun read(fileSpec: String, roamingType: RoamingType = RoamingType.PER_USER): InputStream?
|
||||
|
||||
/**
|
||||
* You must close passed input stream.
|
||||
@@ -41,5 +41,9 @@ public interface StreamProvider {
|
||||
/**
|
||||
* Delete file or directory
|
||||
*/
|
||||
public fun delete(fileSpec: String, roamingType: RoamingType)
|
||||
public fun delete(fileSpec: String, roamingType: RoamingType = RoamingType.PER_USER)
|
||||
}
|
||||
|
||||
public fun StreamProvider.write(fileSpec: String, content: String) {
|
||||
write(fileSpec, content.toByteArray())
|
||||
}
|
||||
@@ -76,7 +76,16 @@ public abstract class BaseRepositoryManager(protected val dir: File) : Repositor
|
||||
FileUtil.delete(dir)
|
||||
}
|
||||
|
||||
protected open fun isPathIgnored(path: String): Boolean = false
|
||||
|
||||
override fun read(path: String): InputStream? {
|
||||
if (isPathIgnored(path)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("$path is ignored")
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
var fileToDelete: File? = null
|
||||
lock.read {
|
||||
val file = File(dir, path)
|
||||
@@ -104,6 +113,13 @@ public abstract class BaseRepositoryManager(protected val dir: File) : Repositor
|
||||
}
|
||||
|
||||
override fun write(path: String, content: ByteArray, size: Int): Boolean {
|
||||
if (isPathIgnored(path)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("$path is ignored")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Write $path")
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class GitRepositoryManager(private val credentialsStore: NotNullLazyValue<Creden
|
||||
|
||||
init {
|
||||
if (ApplicationManager.getApplication()?.isUnitTestMode() != true) {
|
||||
ShutDownTracker.getInstance().registerShutdownTask(object: Runnable {
|
||||
ShutDownTracker.getInstance().registerShutdownTask(object : Runnable {
|
||||
override fun run() {
|
||||
_repository?.close()
|
||||
}
|
||||
@@ -280,7 +280,7 @@ class GitRepositoryManager(private val credentialsStore: NotNullLazyValue<Creden
|
||||
return false
|
||||
}
|
||||
|
||||
repository.commit(with(IdeaCommitMessageFormatter()) { StringBuilder().appendCommitOwnerInfo(true) } .append("Get rid of \$ROOT_CONFIG$ and \$APP_CONFIG").toString())
|
||||
repository.commit(with(IdeaCommitMessageFormatter()) { StringBuilder().appendCommitOwnerInfo(true) }.append("Get rid of \$ROOT_CONFIG$ and \$APP_CONFIG").toString())
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -297,13 +297,9 @@ class GitRepositoryManager(private val credentialsStore: NotNullLazyValue<Creden
|
||||
return node
|
||||
}
|
||||
|
||||
override fun write(path: String, content: ByteArray, size: Int): Boolean {
|
||||
val ignoreRules = getIgnoreRules()
|
||||
override fun isPathIgnored(path: String): Boolean {
|
||||
// add first slash as WorkingTreeIterator does "The ignore code wants path to start with a '/' if possible."
|
||||
if (ignoreRules != null && ignoreRules.isIgnored("/$path", false) == IgnoreNode.MatchResult.IGNORED) {
|
||||
return false
|
||||
}
|
||||
return super.write(path, content, size)
|
||||
return getIgnoreRules()?.isIgnored("/$path", false) == IgnoreNode.MatchResult.IGNORED
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.configurationStore.write
|
||||
import com.intellij.mock.MockVirtualFileSystem
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
@@ -346,11 +347,13 @@ class GitTest : IcsTestCase() {
|
||||
Test fun gitignore() {
|
||||
createLocalRepository()
|
||||
|
||||
repository.add(".gitignore", "*.html")
|
||||
provider.write(".gitignore", "*.html")
|
||||
sync(SyncType.MERGE)
|
||||
|
||||
provider.write("bar.html", "<data />")
|
||||
provider.write("i/am/a/long/path/to/file/foo.html", "<data />")
|
||||
val filePaths = listOf("bar.html", "i/am/a/long/path/to/file/foo.html")
|
||||
for (path in filePaths) {
|
||||
provider.write(path, path)
|
||||
}
|
||||
|
||||
val diff = repository.computeIndexDiff()
|
||||
assertThat(diff.diff()).isFalse()
|
||||
@@ -360,6 +363,10 @@ class GitTest : IcsTestCase() {
|
||||
assertThat(diff.getModified()).isEmpty()
|
||||
assertThat(diff.getUntracked()).isEmpty()
|
||||
assertThat(diff.getUntrackedFolders()).isEmpty()
|
||||
|
||||
for (path in filePaths) {
|
||||
assertThat(provider.read(path)).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createRemoteRepository(branchName: String? = null, initialCommit: Boolean = true) {
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.configurationStore.StreamProvider
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.testFramework.writeChild
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
@@ -28,15 +26,6 @@ import org.junit.Rule
|
||||
import java.nio.file.Path
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
fun StreamProvider.write(path: String, data: ByteArray) {
|
||||
write(path, data, data.size(), RoamingType.PER_USER)
|
||||
}
|
||||
|
||||
fun StreamProvider.write(fileSpec: String, content: String) {
|
||||
val data = content.toByteArray()
|
||||
write(fileSpec, data, data.size(), RoamingType.PER_USER)
|
||||
}
|
||||
|
||||
fun Repository.add(path: String, data: String) = add(path, data.toByteArray())
|
||||
|
||||
fun Repository.add(path: String, data: ByteArray): Repository {
|
||||
|
||||
Reference in New Issue
Block a user