String (@NotNull Project project) { String projectBasePath = project.getBasePath(); if (projectBasePath == null) return ""; GeneralCommandLine commandLine = new GeneralCommandLine() .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) .withWorkDirectory(projectBasePath) .withExePath("git") .withParameters("rev-parse") .withParameters("--abbrev-ref") .withParameters("HEAD"); StringBuilder processOutput = new StringBuilder(); try { OSProcessHandler handler = new OSProcessHandler(commandLine.withCharset(StandardCharsets.UTF_8)); handler.addProcessListener(new CapturingProcessAdapter() { @Override public void processTerminated(@NotNull ProcessEvent event) { if (event.getExitCode() != 0) { LOG.warn("Couldn't fetch current branch name: " + getOutput().getStderr()); } else { processOutput.append(getOutput().getStdout()); } } }); handler.startNotify(); handler.waitFor(); } catch (ExecutionException e) { LOG.warn("Couldn't execute command for getting current branch name", e); } String branch = processOutput.toString(); LOG.debug("Git current branch name: " + branch); return branch.lines().findFirst().orElse(""); }