diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1532639 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +This software is running under the Creative Commons LICENSE Attribution-NonCommercial-ShareAlike 4.0 International +which can be found at https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode \ No newline at end of file diff --git a/src/Ad5001/Gitable/Linux.php b/src/Ad5001/Gitable/Linux.php index a5be448..c54828e 100644 --- a/src/Ad5001/Gitable/Linux.php +++ b/src/Ad5001/Gitable/Linux.php @@ -30,7 +30,7 @@ class Linux extends GitClient { public function gitExec(string $args) : string { chdir($this->dir); $process = proc_open( - "git " . $args, + "cd $this->dir\ngit " . $args, // Temporary working solution. array( 0 => array("pipe", "r"), //S TDIN 1 => array("pipe", "w"), //S TDOUT @@ -38,7 +38,6 @@ class Linux extends GitClient { ), $pipes ); - chdir(DEFAULT_GIT_DIR); if ($process !== false) { $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); @@ -46,12 +45,14 @@ class Linux extends GitClient { fclose($pipes[2]); proc_close($process); + chdir(DEFAULT_GIT_DIR); return $stdout . $stderr; } else { $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); + chdir(DEFAULT_GIT_DIR); return "Error while executing command git " . $args . ": $stderr"; } } @@ -62,19 +63,17 @@ class Linux extends GitClient { @param $path string */ public function cd(string $path): string { + if(substr($this->dir, strlen($this->dir) - 2) !== "/") { + $this->dir .= "/"; + } if(is_dir($this->dir . $path)) { $this->dir = $this->dir . $path; $this->dir = realpath($this->dir); - if(substr($this->dir, strlen($this->dir) - 1) !== "/") { - $this->dir .= "/"; - } return "§aPath set to $this->dir"; } elseif(is_dir($path)) { $this->dir = $path; $this->dir = realpath($this->dir); - if(substr($this->dir, strlen($this->dir) - 1) !== "/") { - $this->dir .= "/"; - }return"§aPath set to $path"; + return"§aPath set to $this->dir"; } else { return "§4Directory $path not found !"; } @@ -89,7 +88,7 @@ class Linux extends GitClient { $whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls'; $process = proc_open( - "$whereIsCommand", + "$whereIsCommand $this->dir", array( 0 => array("pipe", "r"), //S TDIN 1 => array("pipe", "w"), //S TDOUT @@ -97,7 +96,6 @@ class Linux extends GitClient { ), $p ); - chdir(DEFAULT_GIT_DIR); if ($process !== false) { $stdout = stream_get_contents($p[1]); $stderr = stream_get_contents($p[2]); @@ -106,6 +104,7 @@ class Linux extends GitClient { proc_close($process); } + chdir(DEFAULT_GIT_DIR); return $stdout; } diff --git a/src/Ad5001/Gitable/Mac.php b/src/Ad5001/Gitable/Mac.php index 8ad39a3..cc65fa3 100644 --- a/src/Ad5001/Gitable/Mac.php +++ b/src/Ad5001/Gitable/Mac.php @@ -30,7 +30,7 @@ class Mac extends GitClient { public function gitExec(string $args) : string { chdir($this->dir); $process = proc_open( - "git " . $args, + "cd $this->dir\ngit " . $args, array( 0 => array("pipe", "r"), //S TDIN 1 => array("pipe", "w"), //S TDOUT @@ -38,20 +38,20 @@ class Mac extends GitClient { ), $pipes ); - chdir(DEFAULT_GIT_DIR); if ($process !== false) { $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); - + chdir(DEFAULT_GIT_DIR); return $stdout . $stderr; } else { $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); + chdir(DEFAULT_GIT_DIR); return "Error while executing command git " . $args . ": $stderr"; } } @@ -62,19 +62,17 @@ class Mac extends GitClient { @param $path string */ public function cd(string $path): string { + if(substr($this->dir, strlen($this->dir) - 2) !== "/") { + $this->dir .= "/"; + } if(is_dir($this->dir . $path)) { $this->dir = $this->dir . $path; $this->dir = realpath($this->dir); - if(substr($this->dir, strlen($this->dir) - 1) !== "/") { - $this->dir .= "/"; - } return "§aPath set to $this->dir"; } elseif(is_dir($path)) { $this->dir = $path; $this->dir = realpath($this->dir); - if(substr($this->dir, strlen($this->dir) - 1) !== "/") { - $this->dir .= "/"; - }return"§aPath set to $path"; + return"§aPath set to $this->dir"; } else { return "§4Directory $path not found !"; } @@ -89,7 +87,7 @@ class Mac extends GitClient { $whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls'; $process = proc_open( - "$whereIsCommand", + "$whereIsCommand $this->dir", array( 0 => array("pipe", "r"), //S TDIN 1 => array("pipe", "w"), //S TDOUT @@ -97,7 +95,6 @@ class Mac extends GitClient { ), $p ); - chdir(DEFAULT_GIT_DIR); if ($process !== false) { $stdout = stream_get_contents($p[1]); $stderr = stream_get_contents($p[2]); @@ -106,6 +103,7 @@ class Mac extends GitClient { proc_close($process); } + chdir(DEFAULT_GIT_DIR); return $stdout; }