Skip to content

Commit

Permalink
Use full path in ignore dir check
Browse files Browse the repository at this point in the history
Simple dir name doesn't work for directories like:
 jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build

When exceptions are used in .gitignore:
 build/
 !**/src/**/build
 !**/test/**/
  • Loading branch information
goodwinnk committed Jun 10, 2020
1 parent 771c95e commit c08b9dd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bunch-cli/src/main/kotlin/org/jetbrains/bunches/git/ignore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ fun parseGitIgnore(baseGitRoot: File): IgnoreNode? {

// If '.gitignore' file doesn't exist 'ignore' will be null and '==' returns false
// We skip '.gitignore' check in this case
fun checkIgnoreList(dir: File, ignore: IgnoreNode?) =
ignore?.isIgnored(dir.name, dir.isDirectory) == IgnoreNode.MatchResult.IGNORED
fun checkIgnoreList(dir: File, baseGitRoot: File, ignore: IgnoreNode?): Boolean {
if (ignore == null) return false
val repoPath = dir.relativeTo(baseGitRoot).path.replace(File.pathSeparatorChar, '/')
return ignore.isIgnored(repoPath, dir.isDirectory) == IgnoreNode.MatchResult.IGNORED
}

// Git root directory contains ".git" sub-directory.
// Git worktree directory contains ".git" file.
Expand All @@ -32,4 +35,4 @@ fun isNestedGitRoot(dir: File, baseGitRoot: File) =
isGitRoot(dir) && dir != baseGitRoot

fun shouldIgnoreDir(dir: File, baseGitRoot: File, ignore: IgnoreNode?) =
isGitDir(dir) || isNestedGitRoot(dir, baseGitRoot) || checkIgnoreList(dir, ignore)
isGitDir(dir) || isNestedGitRoot(dir, baseGitRoot) || checkIgnoreList(dir, baseGitRoot, ignore)

0 comments on commit c08b9dd

Please sign in to comment.