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.
Merge pull request #13 from y0ung3r/b/8
(#8) Fix relative paths handling
- Loading branch information
Showing
10 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
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
23 changes: 20 additions & 3 deletions
23
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/extensions/GitExtensions.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 |
---|---|---|
@@ -1,14 +1,31 @@ | ||
package com.github.y0ung3r.gitglobalhookslocator.git.extensions | ||
|
||
import com.github.y0ung3r.gitglobalhookslocator.git.Git | ||
import com.github.y0ung3r.gitglobalhookslocator.git.utils.SystemPathUtils | ||
import java.nio.file.Path | ||
|
||
fun Git.getGlobalHooksPath(): String { | ||
val path = executeCommand( | ||
private const val SLASHES_PATTERN = "[/\\\\]" | ||
private const val HOME_PATTERN = "^~$SLASHES_PATTERN" | ||
private const val CURRENT_DIR_PATTERN = "^.$SLASHES_PATTERN" | ||
|
||
fun Git.getGlobalHooksPath(): Path { | ||
val rawPath = executeCommand( | ||
Git.GIT_CONFIG_COMMAND, | ||
Git.GIT_GLOBAL_COMMAND, | ||
Git.GIT_CONFIG_GET_COMMAND, | ||
Git.GIT_HOOKS_PATH_SECTION | ||
) | ||
|
||
return path.value | ||
val targetPath = rawPath.value | ||
.replaceFirst( | ||
Regex(HOME_PATTERN), | ||
SystemPathUtils.getUserHomePath() | ||
) | ||
.replaceFirst( | ||
Regex(CURRENT_DIR_PATTERN), | ||
SystemPathUtils.getCurrentDirectoryPath() | ||
) | ||
|
||
return Path.of(targetPath) | ||
.toAbsolutePath() | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/github/y0ung3r/gitglobalhookslocator/git/utils/SystemPathUtils.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,23 @@ | ||
package com.github.y0ung3r.gitglobalhookslocator.git.utils | ||
|
||
object SystemPathUtils { | ||
private const val USER_HOME_KEY = "user.home" | ||
private const val USER_DIR_KEY = "user.dir" | ||
|
||
@JvmStatic | ||
private fun getSystemPath(key: String): String { | ||
val systemPath = System | ||
.getProperty(key) | ||
.replace("\\", "/") // The replacement eliminates the need to escape the string | ||
|
||
return "$systemPath/" | ||
} | ||
|
||
@JvmStatic | ||
fun getUserHomePath(): String | ||
= getSystemPath(USER_HOME_KEY) | ||
|
||
@JvmStatic | ||
fun getCurrentDirectoryPath(): String | ||
= getSystemPath(USER_DIR_KEY) | ||
} |
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
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
4 changes: 0 additions & 4 deletions
4
src/test/kotlin/com/github/y0ung3r/gitglobalhookslocator/gitTests/SemanticVersionTests.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
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
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 @@ | ||
The current folder is used to generate test data |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.