From 298df3fca385a00003433118a6dd01e88b53551b Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 23 Sep 2016 22:21:59 +0300 Subject: [PATCH] Making some changes ... --- src/Ad5001/Gitable/GitClient.php | 2 +- src/Ad5001/Gitable/Main.php | 22 ++++++++++++++++-- src/Ad5001/Gitable/Windows.php | 40 +++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/Ad5001/Gitable/GitClient.php b/src/Ad5001/Gitable/GitClient.php index 8daf5d0..5ea492f 100644 --- a/src/Ad5001/Gitable/GitClient.php +++ b/src/Ad5001/Gitable/GitClient.php @@ -82,7 +82,7 @@ abstract class GitClient { public abstract function add($path) : string; - public abstract function diff($path) : string; + public abstract function diff() : string; public abstract function status($path) : string; diff --git a/src/Ad5001/Gitable/Main.php b/src/Ad5001/Gitable/Main.php index 55c4101..0f7eb78 100644 --- a/src/Ad5001/Gitable/Main.php +++ b/src/Ad5001/Gitable/Main.php @@ -34,7 +34,7 @@ use pocketmine\Player; class Main extends PluginBase implements Listener { protected $git; - const PREFIX = C::BLACK . "[" . C::LIGHT_GRAY . "Git" . C::BLACK . "] " . C::LIGHT_GRAY; + const PREFIX = C::BLACK .C::BOLD . C::ITALIC . "[" . C::RESET . C::BOLD .C::GRAY . "Git" . C::BLACK . C::ITALIC . "] " . C::RESET . C::GRAY; public function onEnable() { @@ -69,7 +69,25 @@ class Main extends PluginBase implements Listener { case "cd": $this->git->cd($args[1]); - $sender->sendMessage("New path: " . $this->git->getDir()); + $sender->sendMessage(self::PREFIX . "New path: " . $this->git->getDir()); + break; + + case "commit": + unset($args[0]); + $sender->sendMessage(self::PREFIX . $this->git->commit(implode(" ", $args))); + $sender->sendMessage(self::PREFIX . "Commited !"); + break; + + case "checkout": + $sender->sendMessage(self::PREFIX . $this->git->checkout($args[1])); + break; + + case "dir": + $sender->sendMessage(self::PREFIX . $this->git->getDir()); + break; + + case "clone": + $sender->sendMessage(self::PREFIX . $this->git->clone($args[1])); break; } return true; diff --git a/src/Ad5001/Gitable/Windows.php b/src/Ad5001/Gitable/Windows.php index a6bbc85..cd8db8e 100644 --- a/src/Ad5001/Gitable/Windows.php +++ b/src/Ad5001/Gitable/Windows.php @@ -27,17 +27,20 @@ class Windows extends GitClient { public function commit(string $message) : string { - return shell_exec("git commit -m \"$message\""); + $handle = popen("git commit -m \"$message\"", 'r'); + return fread($handle, 2096); } public function push(string $to = "github", string $from = "master") : string { - return shell_exec("git push $to $from"); + $handle = popen("git push $to $from", 'r'); + return fread($handle, 2096); } public function checkout($branch = null) : string { - return shell_exec("git checkout " . (!is_null($branch) ? $this->getBranch() : $branch)); + $handle = popen("git checkout " . (!is_null($branch) ? $this->getBranch() : $branch), 'r'); + return fread($handle, 2096); } @@ -49,17 +52,20 @@ class Windows extends GitClient { public function branch($branch = '') : string { - return shell_exec("git branch " . $branch); + $handle = popen("git branch " . $branch, 'r'); + return fread($handle, 2096); } public function start() : string { - return shell_exec("git init"); + $handle = popen("git init", 'r'); + return fread($handle, 2096); } public function init() : string { - return shell_exec("git init"); + $handle = popen("git init", 'r'); + return fread($handle, 2096); } public function getDir() { @@ -79,38 +85,56 @@ class Windows extends GitClient { public function clone($from) : string { + $handle = popen("git clone $from", 'r'); + return fread($handle, 2096); } public function log() : string { + $handle = popen("git log", 'r'); + return fread($handle, 2096); } public function remove($path) : string { + $handle = popen("git rm $path", 'r'); + return fread($handle, 2096); } public function move($path, $newpath) : string { + $handle = popen("git mv $path $newpath", 'r'); + return fread($handle, 2096); } public function add($path) : string { + $handle = popen("git add $path", 'r'); + return fread($handle, 2096); } - public function diff($path) : string { + public function diff() : string { + $handle = popen("git diff $path", 'r'); + return fread($handle, 2096); } - public function status($path) : string { + public function status() : string { + $handle = popen("git status -s", 'r'); + return fread($handle, 2096); } public function remote($name, $url) : string { + $handle = popen("git remote $name $url", 'r'); + return fread($handle, 2096); } public function pull($to = "github", $from = "master") : string { + $handle = popen("git pull $to $from", 'r'); + return fread($handle, 2096); }