From 4765ca223257f4eb0c0b1ba7a434d6b8fc7272a8 Mon Sep 17 00:00:00 2001 From: David Feeney Date: Thu, 1 Oct 2009 14:56:54 +0200 Subject: [PATCH] Fixed issue 282, Mercurial support in new projects. --- src/IDF/Scm/Mercurial.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 5b83150..b10a78a 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -49,7 +49,12 @@ class IDF_Scm_Mercurial extends IDF_Scm public function isAvailable() { - return true; + try { + $branches = $this->getBranches(); + } catch (IDF_Scm_Exception $e) { + return false; + } + return (count($branches) > 0); } public function findAuthor($author) @@ -86,7 +91,7 @@ class IDF_Scm_Mercurial extends IDF_Scm escapeshellarg($rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; exec($cmd, $out, $ret); - return ($ret == 0); + return ($ret == 0) && (count($out) > 0); } /** @@ -287,8 +292,11 @@ class IDF_Scm_Mercurial extends IDF_Scm * @param bool Get commit diff (false) * @return array Changes */ - public function getCommit($commit='tip', $getdiff=false) + public function getCommit($commit, $getdiff=false) { + if (!$this->isValidRevision($commit)) { + return false; + } $tmpl = ($getdiff) ? Pluf::f('hg_path', 'hg').' log -p -r %s -R %s' : Pluf::f('hg_path', 'hg').' log -r %s -R %s'; $cmd = sprintf($tmpl, @@ -393,8 +401,8 @@ class IDF_Scm_Mercurial extends IDF_Scm continue; } } - $c['tree'] = $c['commit']; - $c['full_message'] = trim($c['full_message']); + $c['tree'] = !empty($c['commit']) ? trim($c['commit']) : ''; + $c['full_message'] = !empty($c['full_message']) ? trim($c['full_message']) : ''; $res[] = (object) $c; return $res; }