Fixed everything on linux (tested) and ported changes to MacOS (not tested). Ready to be released !

This commit is contained in:
Ad5001 2016-11-19 08:44:53 -05:00
parent b267f7f59f
commit 4328064779
2 changed files with 18 additions and 21 deletions

View file

@ -30,7 +30,7 @@ class Linux extends GitClient {
public function gitExec(string $args) : string { public function gitExec(string $args) : string {
chdir($this->dir); chdir($this->dir);
$process = proc_open( $process = proc_open(
"git " . $args, "cd $this->dir\ngit " . $args, // Temporary working solution.
array( array(
0 => array("pipe", "r"), //S TDIN 0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT 1 => array("pipe", "w"), //S TDOUT
@ -38,7 +38,6 @@ class Linux extends GitClient {
), ),
$pipes $pipes
); );
chdir(DEFAULT_GIT_DIR);
if ($process !== false) { if ($process !== false) {
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($pipes[2]);
@ -46,12 +45,14 @@ class Linux extends GitClient {
fclose($pipes[2]); fclose($pipes[2]);
proc_close($process); proc_close($process);
chdir(DEFAULT_GIT_DIR);
return $stdout . $stderr; return $stdout . $stderr;
} else { } else {
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]); fclose($pipes[1]);
fclose($pipes[2]); fclose($pipes[2]);
chdir(DEFAULT_GIT_DIR);
return "Error while executing command git " . $args . ": $stderr"; return "Error while executing command git " . $args . ": $stderr";
} }
} }
@ -62,19 +63,17 @@ class Linux extends GitClient {
@param $path string @param $path string
*/ */
public function cd(string $path): string { public function cd(string $path): string {
if(substr($this->dir, strlen($this->dir) - 2) !== "/") {
$this->dir .= "/";
}
if(is_dir($this->dir . $path)) { if(is_dir($this->dir . $path)) {
$this->dir = $this->dir . $path; $this->dir = $this->dir . $path;
$this->dir = realpath($this->dir); $this->dir = realpath($this->dir);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") {
$this->dir .= "/";
}
return "§aPath set to $this->dir"; return "§aPath set to $this->dir";
} elseif(is_dir($path)) { } elseif(is_dir($path)) {
$this->dir = $path; $this->dir = $path;
$this->dir = realpath($this->dir); $this->dir = realpath($this->dir);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") { return"§aPath set to $this->dir";
$this->dir .= "/";
}return"§aPath set to $path";
} else { } else {
return "§4Directory $path not found !"; return "§4Directory $path not found !";
} }
@ -89,7 +88,7 @@ class Linux extends GitClient {
$whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls'; $whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls';
$process = proc_open( $process = proc_open(
"$whereIsCommand", "$whereIsCommand $this->dir",
array( array(
0 => array("pipe", "r"), //S TDIN 0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT 1 => array("pipe", "w"), //S TDOUT
@ -97,7 +96,6 @@ class Linux extends GitClient {
), ),
$p $p
); );
chdir(DEFAULT_GIT_DIR);
if ($process !== false) { if ($process !== false) {
$stdout = stream_get_contents($p[1]); $stdout = stream_get_contents($p[1]);
$stderr = stream_get_contents($p[2]); $stderr = stream_get_contents($p[2]);
@ -106,6 +104,7 @@ class Linux extends GitClient {
proc_close($process); proc_close($process);
} }
chdir(DEFAULT_GIT_DIR);
return $stdout; return $stdout;
} }

View file

@ -30,7 +30,7 @@ class Mac extends GitClient {
public function gitExec(string $args) : string { public function gitExec(string $args) : string {
chdir($this->dir); chdir($this->dir);
$process = proc_open( $process = proc_open(
"git " . $args, "cd $this->dir\ngit " . $args,
array( array(
0 => array("pipe", "r"), //S TDIN 0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT 1 => array("pipe", "w"), //S TDOUT
@ -38,20 +38,20 @@ class Mac extends GitClient {
), ),
$pipes $pipes
); );
chdir(DEFAULT_GIT_DIR);
if ($process !== false) { if ($process !== false) {
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]); fclose($pipes[1]);
fclose($pipes[2]); fclose($pipes[2]);
proc_close($process); proc_close($process);
chdir(DEFAULT_GIT_DIR);
return $stdout . $stderr; return $stdout . $stderr;
} else { } else {
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]); fclose($pipes[1]);
fclose($pipes[2]); fclose($pipes[2]);
chdir(DEFAULT_GIT_DIR);
return "Error while executing command git " . $args . ": $stderr"; return "Error while executing command git " . $args . ": $stderr";
} }
} }
@ -62,19 +62,17 @@ class Mac extends GitClient {
@param $path string @param $path string
*/ */
public function cd(string $path): string { public function cd(string $path): string {
if(substr($this->dir, strlen($this->dir) - 2) !== "/") {
$this->dir .= "/";
}
if(is_dir($this->dir . $path)) { if(is_dir($this->dir . $path)) {
$this->dir = $this->dir . $path; $this->dir = $this->dir . $path;
$this->dir = realpath($this->dir); $this->dir = realpath($this->dir);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") {
$this->dir .= "/";
}
return "§aPath set to $this->dir"; return "§aPath set to $this->dir";
} elseif(is_dir($path)) { } elseif(is_dir($path)) {
$this->dir = $path; $this->dir = $path;
$this->dir = realpath($this->dir); $this->dir = realpath($this->dir);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") { return"§aPath set to $this->dir";
$this->dir .= "/";
}return"§aPath set to $path";
} else { } else {
return "§4Directory $path not found !"; return "§4Directory $path not found !";
} }
@ -89,7 +87,7 @@ class Mac extends GitClient {
$whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls'; $whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls';
$process = proc_open( $process = proc_open(
"$whereIsCommand", "$whereIsCommand $this->dir",
array( array(
0 => array("pipe", "r"), //S TDIN 0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT 1 => array("pipe", "w"), //S TDOUT
@ -97,7 +95,6 @@ class Mac extends GitClient {
), ),
$p $p
); );
chdir(DEFAULT_GIT_DIR);
if ($process !== false) { if ($process !== false) {
$stdout = stream_get_contents($p[1]); $stdout = stream_get_contents($p[1]);
$stderr = stream_get_contents($p[2]); $stderr = stream_get_contents($p[2]);
@ -106,6 +103,7 @@ class Mac extends GitClient {
proc_close($process); proc_close($process);
} }
chdir(DEFAULT_GIT_DIR);
return $stdout; return $stdout;
} }