From 16810bcaf37ecedadc62abfa27b305f04f5a70cf Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 14 May 2014 15:03:28 +0300 Subject: [PATCH] Treat possible commit as partial hash as fallback. --- src/GitList/Util/Routing.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index c687c3c..f00af82 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -58,11 +58,22 @@ class Routing } } - if ($matchedBranch === null) { - throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); + if ($matchedBranch !== null) { + $commitish = $matchedBranch; } + } - $commitish = $matchedBranch; + if ($commitish === null) { + // We may have partial commit hash as our commitish. + $hash = $slashPosition === false ? $commitishPath : substr($commitishPath, 0, $slashPosition); + if ($repository->hasCommit($hash)) { + $commit = $repository->getCommit($hash); + $commitish = $commit->getHash(); + } + } + + if ($commitish === null) { + throw new EmptyRepositoryException('This repository is currently empty. There are no commits.'); } $commitishLength = strlen($commitish);