Skip to content

Commit

Permalink
Issue 5 - add improved logging where git repository is not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas authored and tom-haines committed Dec 17, 2019
1 parent 78630f4 commit afe8f16
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ plugins {
}

group 'org.jetbrains'
version '0.5.4'

version '0.5.5'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ static void setDefaultBuilder(FrameTitleBuilder defaultBuilder) {
* @return gitHeadFile if exists or null otherwise.
*/
private VirtualFile watchThisProject(Project project) {
final Optional<VirtualFile> gitRepoRootDir = Stream.of(Optional.ofNullable(ProjectUtil.guessProjectDir(project)))
final VirtualFile guessedProjectDir = ProjectUtil.guessProjectDir(project);
final Optional<VirtualFile> gitRepoRootDir = Stream.of(Optional.ofNullable(guessedProjectDir))
.filter(Optional::isPresent)
.map(projectDirOpt -> Optional.ofNullable(projectDirOpt.get().findChild(".git")))
.map(Optional::get)
.map(projectDir -> Optional.ofNullable(projectDir.findChild(".git")))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();

if (!gitRepoRootDir.isPresent()) {
logger.debug("No git repository found");
final String logMsg = createLogMsg(guessedProjectDir);
logger.debug(logMsg);
return null;
}

Expand All @@ -77,6 +81,18 @@ private VirtualFile watchThisProject(Project project) {
return file;
}

@NotNull
static String createLogMsg(VirtualFile guessedProjectDir) {
StringBuilder msg = new StringBuilder("No git repository found in search path: [");
if (guessedProjectDir == null) {
msg.append("none");
} else {
msg.append(guessedProjectDir.getPath());
}
msg.append("]");
return msg.toString();
}

private VirtualFile findGitHeadFile(VirtualFile gitParentDir, Project project) {
VirtualFile gitHeadSymRefFile = gitParentDir.findChild("HEAD");
if (gitHeadSymRefFile != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>io.wisetime.plugins.window.branch</id>
<name>Branch in Window Title</name>
<version>0.5.4</version>
<version>0.5.5</version>
<vendor>Thomas Haines</vendor>

<description><![CDATA[
Expand All @@ -11,14 +11,15 @@
]]></description>

<change-notes><![CDATA[
Version 0.5.5 - Improve logging output in event no git repository is located in project.
Version 0.5.4 - Fix regression from api change in IntelliJ 2019.4+
Version 0.5.3 - Added git worktrees support.
Version 0.5.2 - Improved description and docs.
Version 0.5.0 - Initial release.
]]>
</change-notes>

<idea-version since-build="171.0"/>
<idea-version since-build="172.2103.15"/>

<depends>com.intellij.modules.lang</depends>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.wisetime.idea.branch;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

import com.intellij.openapi.vfs.VirtualFile;
import org.junit.Test;
import org.mockito.Mockito;

/**
* @author thomas.haines
*/
public class BranchNameFrameTitleBuilderTest {

@Test
public void testLogMsgCreate() {
final VirtualFile virtualFile = Mockito.mock(VirtualFile.class);
final String pathInfo = "/some/path";
when(virtualFile.getPath())
.thenReturn(pathInfo);

assertThat(BranchNameFrameTitleBuilder.createLogMsg(virtualFile))
.contains(pathInfo);
}

}

0 comments on commit afe8f16

Please sign in to comment.