diff --git a/src/IDF/Plugin/SyncGit/Serve.php b/src/IDF/Plugin/SyncGit/Serve.php index 42ba320..081c391 100644 --- a/src/IDF/Plugin/SyncGit/Serve.php +++ b/src/IDF/Plugin/SyncGit/Serve.php @@ -192,7 +192,7 @@ class IDF_Plugin_SyncGit_Serve { mkdir($fullpath, 0750, true); exec(sprintf(Pluf::f('idf_exec_cmd_prefix', ''). - 'git --git-dir=%s init', escapeshellarg($fullpath)), + Pluf::f('git_path', 'git').' --git-dir=%s init', escapeshellarg($fullpath)), $out, $res); if ($res != 0) { throw new Exception(sprintf('Init repository error, exit status %d.', $res)); diff --git a/src/IDF/Plugin/SyncMercurial.php b/src/IDF/Plugin/SyncMercurial.php index 2bd8a5a..1c37656 100644 --- a/src/IDF/Plugin/SyncMercurial.php +++ b/src/IDF/Plugin/SyncMercurial.php @@ -77,7 +77,7 @@ class IDF_Plugin_SyncMercurial } $return = 0; $output = array(); - $cmd = sprintf('hg init %s', + $cmd = sprintf(Pluf::f('hg_path', 'hg').' init %s', escapeshellarg($mercurial_path.'/'.$shortname)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $ll = exec($cmd, $output, $return); diff --git a/src/IDF/Plugin/SyncSvn.php b/src/IDF/Plugin/SyncSvn.php index aa30bd5..08e8eed 100644 --- a/src/IDF/Plugin/SyncSvn.php +++ b/src/IDF/Plugin/SyncSvn.php @@ -77,7 +77,7 @@ class IDF_Plugin_SyncSvn } $return = 0; $output = array(); - $cmd = sprintf('svnadmin create %s', + $cmd = sprintf(Pluf::f('svnadmin_path', 'svnadmin').' create %s', escapeshellarg($svn_path.'/'.$shortname)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $ll = exec($cmd, $output, $return); diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index ab1f3c4..33c24d4 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -98,7 +98,7 @@ class IDF_Scm_Git */ public function testHash($hash, $dummy=null) { - $cmd = sprintf('GIT_DIR=%s git cat-file -t %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file -t %s', escapeshellarg($this->repo), escapeshellarg($hash)); $ret = 0; $out = array(); @@ -143,7 +143,7 @@ class IDF_Scm_Git // get the raw log corresponding to this commit to find the // origin of each file. $rawlog = array(); - $cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline -5000 %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -5000 %s', escapeshellarg($this->repo), escapeshellarg($commit)); IDF_Scm::exec($cmd, $rawlog); // We reverse the log to be able to use a fixed efficient @@ -182,7 +182,7 @@ class IDF_Scm_Git if ('tree' != $this->testHash($tree)) { throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree)); } - $cmd_tmpl = 'GIT_DIR=%s git ls-tree%s -t -l %s %s'; + $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree%s -t -l %s %s'; $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), ($recurse) ? ' -r' : '', @@ -209,7 +209,7 @@ class IDF_Scm_Git */ public function getFileInfo($totest, $commit='HEAD') { - $cmd_tmpl = 'GIT_DIR=%s git ls-tree -r -t -l %s'; + $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree -r -t -l %s'; $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), escapeshellarg($commit)); @@ -236,7 +236,7 @@ class IDF_Scm_Git public function getBlob($request_file_info, $dummy=null) { return shell_exec(sprintf(Pluf::f('idf_exec_cmd_prefix', ''). - 'GIT_DIR=%s git cat-file blob %s', + 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file blob %s', escapeshellarg($this->repo), escapeshellarg($request_file_info->hash))); } @@ -249,7 +249,7 @@ class IDF_Scm_Git public function getBranches() { $out = array(); - IDF_Scm::exec(sprintf('GIT_DIR=%s git branch', + IDF_Scm::exec(sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' branch', escapeshellarg($this->repo)), $out); $res = array(); foreach ($out as $b) { @@ -268,12 +268,12 @@ class IDF_Scm_Git public function getCommit($commit='HEAD', $getdiff=false) { if ($getdiff) { - $cmd = sprintf('GIT_DIR=%s git show --date=iso --pretty=format:%s %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' show --date=iso --pretty=format:%s %s', escapeshellarg($this->repo), "'".$this->mediumtree_fmt."'", escapeshellarg($commit)); } else { - $cmd = sprintf('GIT_DIR=%s git log -1 --date=iso --pretty=format:%s %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log -1 --date=iso --pretty=format:%s %s', escapeshellarg($this->repo), "'".$this->mediumtree_fmt."'", escapeshellarg($commit)); @@ -306,7 +306,7 @@ class IDF_Scm_Git */ public function isCommitLarge($commit='HEAD') { - $cmd = sprintf('GIT_DIR=%s git log --numstat -1 --pretty=format:%s %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --numstat -1 --pretty=format:%s %s', escapeshellarg($this->repo), "'commit %H%n'", escapeshellarg($commit)); @@ -339,7 +339,7 @@ class IDF_Scm_Git { if ($n === null) $n = ''; else $n = ' -'.$n; - $cmd = sprintf('GIT_DIR=%s git log%s --date=iso --pretty=format:\'%s\' %s', + $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log%s --date=iso --pretty=format:\'%s\' %s', escapeshellarg($this->repo), $n, $this->mediumtree_fmt, escapeshellarg($commit)); $out = array(); @@ -412,7 +412,7 @@ class IDF_Scm_Git public function getArchiveCommand($commit, $prefix='git-repo-dump/') { return sprintf(Pluf::f('idf_exec_cmd_prefix', ''). - 'GIT_DIR=%s git archive --format=zip --prefix=%s %s', + 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' archive --format=zip --prefix=%s %s', escapeshellarg($this->repo), escapeshellarg($prefix), escapeshellarg($commit)); diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 5d79a5d..ffe4b2d 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -85,7 +85,7 @@ class IDF_Scm_Mercurial */ public function testHash($hash, $dummy=null) { - $cmd = sprintf('hg log -R %s -r %s', + $cmd = sprintf(Pluf::f('hg_path', 'hg').' log -R %s -r %s', escapeshellarg($this->repo), escapeshellarg($hash)); $ret = 0; @@ -139,7 +139,7 @@ class IDF_Scm_Mercurial if ('commit' != $this->testHash($tree)) { throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree)); } - $cmd_tmpl = 'hg manifest -R %s --debug -r %s'; + $cmd_tmpl = Pluf::f('hg_path', 'hg').' manifest -R %s --debug -r %s'; $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $tree, ($recurse) ? '' : ''); $out = array(); $res = array(); @@ -195,7 +195,7 @@ class IDF_Scm_Mercurial */ public function getFileInfo($totest, $commit='tip') { - $cmd_tmpl = 'hg manifest -R %s --debug -r %s'; + $cmd_tmpl = Pluf::f('hg_path', 'hg').' manifest -R %s --debug -r %s'; $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $commit); $out = array(); $res = array(); @@ -248,7 +248,7 @@ class IDF_Scm_Mercurial */ public function getBlob($request_file_info, $dummy=null) { - return IDF_Scm::shell_exec(sprintf('hg cat -R %s -r %s %s', + return IDF_Scm::shell_exec(sprintf(Pluf::f('hg_path', 'hg').' cat -R %s -r %s %s', escapeshellarg($this->repo), $dummy, escapeshellarg($this->repo . '/' . $request_file_info->file))); @@ -262,7 +262,7 @@ class IDF_Scm_Mercurial public function getBranches() { $out = array(); - IDF_Scm::exec(sprintf('hg branches -R %s', + IDF_Scm::exec(sprintf(Pluf::f('hg_path', 'hg').' branches -R %s', escapeshellarg($this->repo)), $out); $res = array(); foreach ($out as $b) { @@ -282,7 +282,7 @@ class IDF_Scm_Mercurial public function getCommit($commit='tip', $getdiff=false) { $tmpl = ($getdiff) ? - 'hg log -p -r %s -R %s' : 'hg log -r %s -R %s'; + Pluf::f('hg_path', 'hg').' log -p -r %s -R %s' : Pluf::f('hg_path', 'hg').' log -r %s -R %s'; $cmd = sprintf($tmpl, escapeshellarg($commit), escapeshellarg($this->repo)); $out = array(); @@ -325,7 +325,7 @@ class IDF_Scm_Mercurial */ public function getChangeLog($commit='tip', $n=10) { - $cmd = sprintf('hg log -R %s -l%s ', escapeshellarg($this->repo), $n, $commit); + $cmd = sprintf(Pluf::f('hg_path', 'hg').' log -R %s -l%s ', escapeshellarg($this->repo), $n, $commit); $out = array(); IDF_Scm::exec($cmd, $out); return self::parseLog($out, 6); @@ -399,7 +399,7 @@ class IDF_Scm_Mercurial public function getArchiveCommand($commit, $prefix='') { return sprintf(Pluf::f('idf_exec_cmd_prefix', ''). - 'hg archive --type=zip -R %s -r %s -', + Pluf::f('hg_path', 'hg').' archive --type=zip -R %s -r %s -', escapeshellarg($this->repo), escapeshellarg($commit)); } diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index e2f7a61..b98437f 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -108,7 +108,7 @@ class IDF_Scm_Svn } // Else, test the path on revision - $cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo.'/'.$path), @@ -146,7 +146,7 @@ class IDF_Scm_Svn */ public function filesAtCommit($rev='HEAD', $folder='') { - $cmd = sprintf('svn ls --xml --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo.'/'.$folder), @@ -190,7 +190,7 @@ class IDF_Scm_Svn */ private function getCommitMessage($file, $rev='HEAD') { - $cmd = sprintf('svn log --xml --limit 1 --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml --limit 1 --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($file), @@ -210,7 +210,7 @@ class IDF_Scm_Svn */ public function getFileInfo($totest, $rev='HEAD') { - $cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo.'/'.$totest), @@ -242,7 +242,7 @@ class IDF_Scm_Svn */ public function getBlob($request_file_info, $rev) { - $cmd = sprintf('svn cat --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' cat --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo.'/'.$request_file_info->fullpath), @@ -273,7 +273,7 @@ class IDF_Scm_Svn public function getCommit($rev='HEAD', $getdiff=false) { $res = array(); - $cmd = sprintf('svn log --xml -v --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml -v --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo), @@ -303,7 +303,7 @@ class IDF_Scm_Svn // We have a locally hosted repository, we can query it with // svnlook $repo = substr($this->repo, 7); - $cmd = sprintf('svnlook changed -r %s %s', + $cmd = sprintf(Pluf::f('svnlook_path', 'svnlook').' changed -r %s %s', escapeshellarg($commit), escapeshellarg($repo)); $out = IDF_Scm::shell_exec($cmd); @@ -314,7 +314,7 @@ class IDF_Scm_Svn private function getDiff($rev='HEAD') { $res = array(); - $cmd = sprintf('svn diff -c %s --username=%s --password=%s %s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' diff -c %s --username=%s --password=%s %s', escapeshellarg($rev), escapeshellarg($this->username), escapeshellarg($this->password), @@ -334,7 +334,7 @@ class IDF_Scm_Svn public function getChangeLog($rev='HEAD', $n=10) { $res = array(); - $cmd = sprintf('svn log --xml -v --limit %s --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml -v --limit %s --username=%s --password=%s %s@%s', escapeshellarg($n), escapeshellarg($this->username), escapeshellarg($this->password), @@ -383,7 +383,7 @@ class IDF_Scm_Svn public function getProperties($rev, $path='') { $res = array(); - $cmd = sprintf('svn proplist --xml --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' proplist --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo.'/'.$path), @@ -417,7 +417,7 @@ class IDF_Scm_Svn private function getProperty($property, $rev, $path='') { $res = array(); - $cmd = sprintf('svn propget --xml %s --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' propget --xml %s --username=%s --password=%s %s@%s', escapeshellarg($property), escapeshellarg($this->username), escapeshellarg($this->password), @@ -440,7 +440,7 @@ class IDF_Scm_Svn public function getLastCommit($rev='HEAD') { $xmlInfo = ''; - $cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', + $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), escapeshellarg($this->repo), diff --git a/src/IDF/conf/idf.php-dist b/src/IDF/conf/idf.php-dist index f9bb11d..416fdd8 100644 --- a/src/IDF/conf/idf.php-dist +++ b/src/IDF/conf/idf.php-dist @@ -215,4 +215,16 @@ $cfg['allowed_scm'] = array('git' => 'IDF_Scm_Git', # variables not being set correctly. Note the trailing space. # $cfg['idf_exec_cmd_prefix'] = '/usr/bin/env -i '; +# Path to the SCM binaries. These binaries are not necessarily in +# the path of your webserver or fastcgi process. In that case you +# may need to set the path manually here. This is the case with OSX. +# To know which path you need to provide, just run: +# $ which git +# from the command line. This will give you the path to git. +# $cfg['svn_path'] = 'svn'; +# $cfg['svnlook_path'] = 'svnlook'; +# $cfg['svnadmin_path'] = 'svnadmin'; +# $cfg['hg_path'] = 'hg'; +# $cfg['git_path'] = 'git'; + return $cfg;