From ab7ffc181b3d27a13e908a4e2b331a085b09f70b Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Fri, 18 Jan 2013 13:34:29 -0200 Subject: [PATCH] Fixes #208 --- src/GitList/Util/Repository.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 206c757..4ab0202 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -200,25 +200,23 @@ class Repository $branch = $matches[1]; } else { // Otherwise, attempt to detect the ref using a list of the project's branches and tags - $valid_refs = array_merge((array) $repository->getBranches(), (array) $repository->getTags()); - foreach ($valid_refs as $k => $v) { - if (!preg_match(sprintf("#^%s/#", preg_quote($v, '#')), $input)) { - unset($valid_refs[$k]); + $validRefs = array_merge((array) $repository->getBranches(), (array) $repository->getTags()); + foreach ($validRefs as $key => $ref) { + if (!preg_match(sprintf("#^%s/#", preg_quote($ref, '#')), $input)) { + unset($validRefs[$key]); } } // No exact ref match, so just try our best - if (count($valid_refs) > 1) { + if (count($validRefs) > 1) { preg_match('/([^\/]+)(.*)/', $input, $matches); $branch = preg_replace('/^\/|\/$/', '', $matches[1]); } else { // Extract branch name - $branch = array_shift($valid_refs); + $branch = array_shift($validRefs); } } - $tree = trim(str_replace($branch, "", $input), "/"); - return array($branch, $tree); }