Skip to content

Commit 1e0e6a0

Browse files
committed
feat: support windows
1 parent f2923e9 commit 1e0e6a0

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/main/kotlin/com/huayi/intellijplatform/gitstats/utils/GitUtils.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.huayi.intellijplatform.gitstats.utils
22

33
import git4idea.config.GitExecutableManager
4+
import git4idea.config.GitExecutableDetector
45
import java.util.concurrent.TimeUnit
56
import com.intellij.openapi.project.Project
67

@@ -29,7 +30,11 @@ data class CommitFilesStats(
2930
class GitUtils(project: Project) {
3031
private val gitExecutablePath: String = GitExecutableManager.getInstance().getExecutable(project).exePath
3132
private val basePath: String = project.basePath as String
33+
private val gitBashExecutablePath: String? = GitExecutableDetector.getBashExecutablePath(gitExecutablePath)
3234

35+
init {
36+
println(gitBashExecutablePath)
37+
}
3338
// companion object {
3439
// fun getGitExecutablePath(project: Project): String {
3540
// return GitExecutableManager.getInstance().getExecutable(project).exePath
@@ -41,9 +46,9 @@ class GitUtils(project: Project) {
4146
): Array<UserStats> {
4247
val os = Utils.getOS()
4348
val command = listOf(
44-
if (os == "Windows") "cmd" else "/bin/sh",
49+
if (os == "Windows") gitBashExecutablePath ?: "cmd" else "/bin/sh",
4550
if (os == "Windows") "/c" else "-c",
46-
"$gitExecutablePath log --format=\"%aN\" | sort -u | while read name; do echo \"\$name\"; git log --author=\"\$name\" --pretty=tformat: --since==\"$startDate\" --until=\"$endDate\" --numstat | awk '{ add += \$1; subs += \$2; file++ } END { printf \"added lines: %s, removed lines: %s, modified files: %s\\n\", add ? add : 0, subs ? subs : 0, file ? file : 0 }' -; done"
51+
"$gitExecutablePath log --format=\"%aN\" | sort -u | while read name; do echo \"\$name\"; git log --author=\"\$name\" --pretty=\"tformat:\" --since=\"$startDate\" --until=\"$endDate\" --numstat | awk '{ add += \$1; subs += \$2; file++ } END { printf \"added lines: %s, removed lines: %s, modified files: %s\\n\", add ? add : 0, subs ? subs : 0, file ? file : 0 }' -; done"
4752
)
4853
val process = Utils.runCommand(basePath, command, timeoutAmount, timeUnit)
4954
val regex = Regex("(.+)\\n+added lines: (\\d*), removed lines: (\\d+), modified files: (\\d+)")
Lines changed: 6 additions & 7 deletions
Loading
Lines changed: 6 additions & 7 deletions
Loading

0 commit comments

Comments
 (0)