Browse Source

First commit done wwith gitable on Windows !

tags/v1.0
Ad MCPE 3 years ago
parent
commit
09f7d8dc9a
4 changed files with 26 additions and 54 deletions
  1. 1
    1
      config.yml
  2. 1
    1
      resources/win.yml
  3. 1
    1
      src/Ad5001/Gitable/Main.php
  4. 23
    51
      src/Ad5001/Gitable/Windows.php

+ 1
- 1
config.yml View File

@@ -1,4 +1,4 @@
# Welcome to windows Gitable's config !
# Select here the path of the git executable (if you did
# 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"

+ 1
- 1
resources/win.yml View File

@@ -1,4 +1,4 @@
# Welcome to windows Gitable's config !
# Select here the path of the git executable (if you did
# 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"

+ 1
- 1
src/Ad5001/Gitable/Main.php View File

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

+ 23
- 51
src/Ad5001/Gitable/Windows.php View File

@@ -28,17 +28,9 @@ class Windows extends GitClient {
@param $args string
*/
public function gitExec(string $args) : string {
proc_open(
"cd " . $this->dir,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
);
chdir($this->dir);
$process = proc_open(
"git " . $args,
"\"$this->executable\" " . $args,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
@@ -46,15 +38,7 @@ class Windows extends GitClient {
),
$pipes
);
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) {
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
@@ -62,13 +46,13 @@ class Windows extends GitClient {
fclose($pipes[2]);
proc_close($process);
return (string) $stdout;
return $stdout . $stderr;
} else {
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
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 {
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) !== "/") {
$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 $path";
} else {
return "§4Directory $path not found !";
}
@@ -100,44 +85,28 @@ class Windows extends GitClient {
Return all files and dirs from the current directory
*/
public function ls() : string {
proc_open(
"cd " . $this->dir,
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$a
);
chdir($this->dir);
$whereIsCommand = (PHP_OS == 'WINNT') ? 'dir' : 'ls';
$process = proc_open(
"$whereIsCommand $command",
"$whereIsCommand",
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
2 => array("pipe", "w"), //S TDERR
),
$pipes
);
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
$p
);
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]);
$stdout = stream_get_contents($p[1]);
$stderr = stream_get_contents($p[2]);
fclose($p[1]);
fclose($p[2]);
proc_close($process);
return $stdout;
}
return $stdout;
}


@@ -147,7 +116,7 @@ class Windows extends GitClient {
public function initcheck() {
$this->executable = $this->main->getConfig()->get("executable_path");
$process = proc_open(
'"$this->executable"'." --version",
"\"$this->executable\" --version",
array(
0 => array("pipe", "r"), //S TDIN
1 => array("pipe", "w"), //S TDOUT
@@ -162,9 +131,12 @@ class Windows extends GitClient {
fclose($pipes[2]);
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->setEnabled(false);
} else {
$this->main->getLogger()->info("Loaded git: $stdout");
}
}
}

Loading…
Cancel
Save