Skip to content

Commit

Permalink
Merge pull request #3426 from objectionary/qf
Browse files Browse the repository at this point in the history
return hash if tag is the hash
  • Loading branch information
yegor256 authored Oct 20, 2024
2 parents 340e4c7 + 404ec0a commit b5ebe68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChText.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
}

0 comments on commit b5ebe68

Please sign in to comment.