diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChText.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChText.java index ce07481025..643f026c79 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChText.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChText.java @@ -75,6 +75,20 @@ public ChText(final Path file, final String tag) { @Override public String value() { + final String hash; + if (this.tag.matches("[0-9a-fA-F]{40}")) { + hash = this.tag; + } else { + hash = this.inside(); + } + return hash; + } + + /** + * Find and return Git SHA for the given tag (or throw if not found). + * @return The Git SHA + */ + private String inside() { return new Unchecked<>( new Mapped<>( Text::asString, diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/hash/ChTextTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/hash/ChTextTest.java index ad1e6c91bf..348e717cc4 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/hash/ChTextTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/hash/ChTextTest.java @@ -115,4 +115,16 @@ void readsHashByNonExistedTag() { BinarizeParseTest.TO_ADD_MESSAGE ); } + + @Test + void readsHashByHash() { + MatcherAssert.assertThat( + "Hash must be itself, even if it's absent in the table", + new ChText( + () -> "", + "434868a411b9741fdd4f8a38a5c576e8733345c9" + ).value(), + Matchers.equalTo("434868a411b9741fdd4f8a38a5c576e8733345c9") + ); + } }