diff --git a/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/GitCommitSearchExtension.java b/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/GitCommitSearchExtension.java index 77ebb50f380..cb2363b8e4f 100644 --- a/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/GitCommitSearchExtension.java +++ b/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/GitCommitSearchExtension.java @@ -20,6 +20,8 @@ @Component public class GitCommitSearchExtension extends AbstractExtension implements SearchExtension { + private final Pattern shaPattern = Pattern.compile("[a-f0-9]{40}|[a-f0-9]{7}"); + private final GitService gitService; private final URIBuilder uriBuilder; @@ -46,7 +48,7 @@ public GitCommitSearchProvider() { @Override public boolean isTokenSearchable(String token) { - return Pattern.matches("[a-f0-9]{40}", token); + return shaPattern.matcher(token).matches(); } @Override diff --git a/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/client/impl/DefaultGitClient.java b/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/client/impl/DefaultGitClient.java index cc28ad25e0f..c7f6d6f1792 100644 --- a/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/client/impl/DefaultGitClient.java +++ b/ontrack-extension-git/src/main/java/net/nemerosa/ontrack/extension/git/client/impl/DefaultGitClient.java @@ -186,11 +186,12 @@ public boolean isCommitDefined(String commit) { public GitCommit getCommitFor(String commit) { try { Repository repo = repository.git().getRepository(); - return toCommit( - new RevWalk(repo).parseCommit( - repo.resolve(commit + "^0") - ) - ); + ObjectId objectId = repo.resolve(commit + "^0"); + if (objectId != null) { + return toCommit(new RevWalk(repo).parseCommit(objectId)); + } else { + return null; + } } catch (IOException e) { return null; }