VirtusLab / git-machete-intellij-plugin

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
MIT License
134 stars 16 forks source link

Enable running `machete-status-branch hook` both in tests and the actual plugin on Windows #760

Closed Beniamin-Dolega closed 2 years ago

Beniamin-Dolega commented 3 years ago

testCommon/src/test/resources/common.sh:39 Make this four lines of code (40-43) work on windows.

PawelLipski commented 2 years ago

Given that you @mkondratek will soon switch to Windows for a moment, this might be a good occasion to check. It'll be mostly a matter of making sure that com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor#executeHookFor properly launches .git/hooks/machete-status/branch as a Bash script... TBD how to ensure that on Windows.

Actually, would be good to check how e.g. JGit launches git hooks: org.eclipse.jgit.hooks.GitHook#doRun seems a good place to start (org.eclipse.jgit.util.FS_Win32_Cygwin#runInShell FTW) — maybe actually delegating execution of hooks to JGit (via GitCoreRepository) would be the best solution here, to make both backendImpl:test and hooks in the actual execution of the plugin work.

mkondratek commented 2 years ago

The problem with the hook on windows comes from subprocess creation. There we need to run bash script but we do not know if the user actually uses some git bash (or any other tool enabling that).

Stacktrace ```stacktrace An error occurred while running machete-status-branch hook (C:\Users\mikson\IdeaProjects\git-machete-intellij-plugin\.git\hooks\machete-status-branch)for master; ignoring the hook java.io.IOException: Cannot run program "C:\Users\mikson\IdeaProjects\git-machete-intellij-plugin\.git\hooks\machete-status-branch" (in directory "C:\Users\mikson\IdeaProjects\git-machete-intellij-plugin"): CreateProcess error=193, %1 nie jest prawidłową aplikacją systemu Win32 at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor.executeHookFor_aroundBody0(StatusBranchHookExecutor.java:79) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor$AjcClosure1.run(StatusBranchHookExecutor.java:1) at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:167) at com.jcabi.aspects.aj.MethodLogger.wrap(MethodLogger.java:211) at com.jcabi.aspects.aj.MethodLogger.ajc$inlineAccessMethod$com_jcabi_aspects_aj_MethodLogger$com_jcabi_aspects_aj_MethodLogger$wrap(MethodLogger.java:1) at com.jcabi.aspects.aj.MethodLogger.wrapMethod(MethodLogger.java:167) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor.executeHookFor(StatusBranchHookExecutor.java:49) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor.lambda$deriveHookOutputFor$da55feee$1(StatusBranchHookExecutor.java:114) at io.vavr.control.Try.of(Try.java:75) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor.lambda$deriveHookOutputFor$3(StatusBranchHookExecutor.java:114) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) at com.virtuslab.gitmachete.backend.impl.hooks.StatusBranchHookExecutor.deriveHookOutputFor(StatusBranchHookExecutor.java:113) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository$CreateGitMacheteRepositoryAux.createGitMacheteRootBranch(GitMacheteRepository.java:402) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository$CreateGitMacheteRepositoryAux.lambda$createSnapshot$4cd04c2b$1(GitMacheteRepository.java:311) at io.vavr.control.Try.of(Try.java:75) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository$CreateGitMacheteRepositoryAux.lambda$createSnapshot$0(GitMacheteRepository.java:311) at io.vavr.collection.List.map(List.java:1042) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository$CreateGitMacheteRepositoryAux.createSnapshot(GitMacheteRepository.java:311) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository.createSnapshotForLayout_aroundBody0(GitMacheteRepository.java:83) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository$AjcClosure1.run(GitMacheteRepository.java:1) at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:167) at com.jcabi.aspects.aj.MethodLogger.wrap(MethodLogger.java:211) at com.jcabi.aspects.aj.MethodLogger.ajc$inlineAccessMethod$com_jcabi_aspects_aj_MethodLogger$com_jcabi_aspects_aj_MethodLogger$wrap(MethodLogger.java:1) at com.jcabi.aspects.aj.MethodLogger.wrapMethod(MethodLogger.java:167) at com.virtuslab.gitmachete.backend.impl.GitMacheteRepository.createSnapshotForLayout(GitMacheteRepository.java:82) at com.virtuslab.gitmachete.frontend.ui.impl.table.GitMacheteRepositoryUpdateBackgroundable.lambda$updateRepositorySnapshot$47bf2c18$1(GitMacheteRepositoryUpdateBackgroundable.java:92) at io.vavr.control.Try.of(Try.java:75) at com.virtuslab.gitmachete.frontend.ui.impl.table.GitMacheteRepositoryUpdateBackgroundable.updateRepositorySnapshot(GitMacheteRepositoryUpdateBackgroundable.java:89) at com.virtuslab.gitmachete.frontend.ui.impl.table.GitMacheteRepositoryUpdateBackgroundable.run(GitMacheteRepositoryUpdateBackgroundable.java:64) at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442) at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493) at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:244) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683) at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176) at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:244) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.io.IOException: CreateProcess error=193, %1 nie jest prawidłową aplikacją systemu Win32 at java.base/java.lang.ProcessImpl.create(Native Method) at java.base/java.lang.ProcessImpl.(ProcessImpl.java:487) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ... 50 more ```
mkondratek commented 2 years ago

Not a solution but I improved code and error handling a bit: https://github.com/VirtusLab/git-machete-intellij-plugin/pull/822