generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#10) Improve tracking of changes in hooks folder
- Loading branch information
Showing
26 changed files
with
660 additions
and
390 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/HookEvent.kt
This file was deleted.
Oops, something went wrong.
68 changes: 0 additions & 68 deletions
68
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/HooksFolder.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/HooksFolderVisitor.kt
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/ObservableHooksFolder.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...n/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/exceptions/HookNotFoundException.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/hooks/HookName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.y0ung3r.gitglobalhookslocator.git.hooks | ||
|
||
import com.github.y0ung3r.gitglobalhookslocator.git.hooks.exceptions.UnsupportedHookNameException | ||
import gnu.trove.Equality | ||
import java.io.File | ||
import java.nio.file.Path | ||
import kotlin.io.path.nameWithoutExtension | ||
|
||
class HookName private constructor(private val source: String) : Comparable<HookName> { | ||
companion object { | ||
@JvmStatic | ||
val supportedHooks = arrayOf( | ||
"pre-commit", | ||
"prepare-commit-msg", | ||
"commit-msg", | ||
"post-commit", | ||
"applypatch-msg", | ||
"pre-applypatch", | ||
"post-applypatch", | ||
"pre-rebase", | ||
"post-rewrite", | ||
"post-checkout", | ||
"post-merge", | ||
"pre-push", | ||
"pre-auto-gc" | ||
) | ||
|
||
@JvmStatic | ||
fun isSupportedHook(hookPath: Path): Boolean | ||
= supportedHooks.any { | ||
hookPath.nameWithoutExtension.contains(it) } | ||
|
||
@JvmStatic | ||
fun create(file: File): HookName | ||
= HookName(file.nameWithoutExtension) | ||
|
||
@JvmStatic | ||
fun create(path: Path): HookName | ||
= HookName(path.nameWithoutExtension) | ||
} | ||
|
||
val value: String | ||
= supportedHooks | ||
.firstOrNull { source.contains(it) } | ||
?: throw UnsupportedHookNameException(source) | ||
|
||
override fun compareTo(other: HookName): Int | ||
= other.value.compareTo(value) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
val name = other as? HookName | ||
|
||
return when { | ||
name == null -> false | ||
compareTo(name) == 0 -> true | ||
else -> false | ||
} | ||
} | ||
|
||
override fun hashCode(): Int | ||
= value.hashCode() | ||
} |
Oops, something went wrong.