First commit done wwith gitable on Windows !

This commit is contained in:
Ad MCPE 2016-11-19 10:50:57 +01:00
parent 7f803ecd49
commit 09f7d8dc9a
4 changed files with 26 additions and 54 deletions

View file

@ -1,4 +1,4 @@
# Welcome to windows Gitable's config ! # Welcome to windows Gitable's config !
# Select here the path of the git executable (if you did # Select here the path of the git executable (if you did
# not modify it while installing git, it should work.) # not modify it while installing git, it should work.)
executable_path: C:\Program Files\Git\bin\git.exe executable_path: "C:\\Program Files\\Git\\bin\\git.exe"

View file

@ -1,4 +1,4 @@
# Welcome to windows Gitable's config ! # Welcome to windows Gitable's config !
# Select here the path of the git executable (if you did # Select here the path of the git executable (if you did
# not modify it while installing git, it should work.) # not modify it while installing git, it should work.)
executable_path: C:\Program Files\Git\bin\git.exe executable_path: "C:\\Program Files\\Git\\bin\\git.exe"

View file

@ -78,7 +78,7 @@ class Main extends PluginBase implements Listener {
case 'git': case 'git':
if(count($args) >= 2) { if(count($args) >= 1) {
switch($args[0]) { switch($args[0]) {

View file

@ -28,17 +28,9 @@ class Windows extends GitClient {
@param $args string @param $args string
*/ */
public function gitExec(string $args) : string { public function gitExec(string $args) : string {
proc_open( chdir($this->dir);
"cd " . $this->dir,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
);
$process = proc_open( $process = proc_open(
"git " . $args, "\"$this->executable\" " . $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
@ -46,15 +38,7 @@ class Windows extends GitClient {
), ),
$pipes $pipes
); );
proc_open( chdir(DEFAULT_GIT_DIR);
"cd " . DEFAULT_GIT_DIR,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
);
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]);
@ -62,13 +46,13 @@ class Windows extends GitClient {
fclose($pipes[2]); fclose($pipes[2]);
proc_close($process); proc_close($process);
return (string) $stdout; 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]);
return "Error while executing command "."git " . $args . ": $stderr"; return "Error while executing command git " . $args . ": $stderr";
} }
} }
@ -79,17 +63,18 @@ class Windows extends GitClient {
*/ */
public function cd(string $path): string { public function cd(string $path): string {
if(is_dir($this->dir . $path)) { if(is_dir($this->dir . $path)) {
$this->dir .= $path; $this->dir = $this->dir . $path;
$this->dir = realpath($this->dir);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") { if(substr($this->dir, strlen($this->dir) - 1) !== "/") {
$this->dir .= "/"; $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);
if(substr($this->dir, strlen($this->dir) - 1) !== "/") { if(substr($this->dir, strlen($this->dir) - 1) !== "/") {
$this->dir .= "/"; $this->dir .= "/";
} }return"§aPath set to $path";
return "§aPath set to $path";
} else { } else {
return "§4Directory $path not found !"; return "§4Directory $path not found !";
} }
@ -100,44 +85,28 @@ class Windows extends GitClient {
Return all files and dirs from the current directory Return all files and dirs from the current directory
*/ */
public function ls() : string { public function ls() : string {
proc_open( chdir($this->dir);
"cd " . $this->dir,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
);
$whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls'; $whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls';
$process = proc_open( $process = proc_open(
"$whereIsCommand $command", "$whereIsCommand",
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
2 => array("pipe", "w"), //S TDERR 2 => array("pipe", "w"), //S TDERR
), ),
$pipes $p
);
proc_open(
"cd " . DEFAULT_GIT_DIR,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
); );
chdir(DEFAULT_GIT_DIR);
if ($process !== false) { if ($process !== false) {
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($p[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($p[2]);
fclose($pipes[1]); fclose($p[1]);
fclose($pipes[2]); fclose($p[2]);
proc_close($process); proc_close($process);
return $stdout;
} }
return $stdout;
} }
@ -147,7 +116,7 @@ class Windows extends GitClient {
public function initcheck() { public function initcheck() {
$this->executable = $this->main->getConfig()->get("executable_path"); $this->executable = $this->main->getConfig()->get("executable_path");
$process = proc_open( $process = proc_open(
'"$this->executable"'." --version", "\"$this->executable\" --version",
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
@ -162,9 +131,12 @@ class Windows extends GitClient {
fclose($pipes[2]); fclose($pipes[2]);
proc_close($process); proc_close($process);
if(strpos($stdout, "git version") == false) { if($stdout == '') {
$this->main->getLogger()->info("Git error: $stderr");
$this->main->getLogger()->critical("Executable wasn't found at path $this->executable. Be sure that you installed git and that the path in the config is the executable path."); $this->main->getLogger()->critical("Executable wasn't found at path $this->executable. Be sure that you installed git and that the path in the config is the executable path.");
$this->main->setEnabled(false); $this->main->setEnabled(false);
} else {
$this->main->getLogger()->info("Loaded git: $stdout");
} }
} }
} }