-
-
Couldn't load subscription status.
- Fork 109
Added 'git clean' and improved code comments #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,10 @@ class GitRepository implements IGit | |
| protected $cwd; | ||
|
|
||
|
|
||
| /** | ||
| * @param string | ||
| */ | ||
| /** | ||
| * @param string | ||
| * @throws GitException | ||
| */ | ||
| public function __construct($repository) | ||
| { | ||
| if(basename($repository) === '.git') | ||
|
|
@@ -50,7 +51,7 @@ public function getRepositoryPath() | |
| * `git tag <name>` | ||
| * @param string | ||
| * @param array|NULL | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function createTag($name, $options = NULL) | ||
|
|
@@ -65,7 +66,7 @@ public function createTag($name, $options = NULL) | |
| * Removes tag. | ||
| * `git tag -d <name>` | ||
| * @param string | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function removeTag($name) | ||
|
|
@@ -84,7 +85,7 @@ public function removeTag($name) | |
| * `git tag -d <old>` | ||
| * @param string | ||
| * @param string | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function renameTag($oldName, $newName) | ||
|
|
@@ -99,10 +100,11 @@ public function renameTag($oldName, $newName) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns list of tags in repo. | ||
| * @return string[]|NULL NULL => no tags | ||
| */ | ||
| /** | ||
| * Returns list of tags in repo. | ||
| * @return string[]|NULL NULL => no tags | ||
| * @throws GitException | ||
| */ | ||
| public function getTags() | ||
| { | ||
| return $this->extractFromCommand('git tag', 'trim'); | ||
|
|
@@ -114,7 +116,7 @@ public function getTags() | |
| * `git merge <options> <name>` | ||
| * @param string | ||
| * @param array|NULL | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function merge($branch, $options = NULL) | ||
|
|
@@ -131,7 +133,7 @@ public function merge($branch, $options = NULL) | |
| * (optionaly) `git checkout <name>` | ||
| * @param string | ||
| * @param bool | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function createBranch($name, $checkout = FALSE) | ||
|
|
@@ -154,7 +156,7 @@ public function createBranch($name, $checkout = FALSE) | |
| * Removes branch. | ||
| * `git branch -d <name>` | ||
| * @param string | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function removeBranch($name) | ||
|
|
@@ -171,7 +173,7 @@ public function removeBranch($name) | |
| * Gets name of current branch | ||
| * `git branch` + magic | ||
| * @return string | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| */ | ||
| public function getCurrentBranchName() | ||
| { | ||
|
|
@@ -196,10 +198,11 @@ public function getCurrentBranchName() | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns list of all (local & remote) branches in repo. | ||
| * @return string[]|NULL NULL => no branches | ||
| */ | ||
| /** | ||
| * Returns list of all (local & remote) branches in repo. | ||
| * @return string[]|NULL NULL => no branches | ||
| * @throws GitException | ||
| */ | ||
| public function getBranches() | ||
| { | ||
| return $this->extractFromCommand('git branch -a', function($value) { | ||
|
|
@@ -208,10 +211,11 @@ public function getBranches() | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns list of local branches in repo. | ||
| * @return string[]|NULL NULL => no branches | ||
| */ | ||
| /** | ||
| * Returns list of local branches in repo. | ||
| * @return string[]|NULL NULL => no branches | ||
| * @throws GitException | ||
| */ | ||
| public function getLocalBranches() | ||
| { | ||
| return $this->extractFromCommand('git branch', function($value) { | ||
|
|
@@ -224,7 +228,7 @@ public function getLocalBranches() | |
| * Checkout branch. | ||
| * `git checkout <branch>` | ||
| * @param string | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function checkout($name) | ||
|
|
@@ -239,7 +243,7 @@ public function checkout($name) | |
| * Removes file(s). | ||
| * `git rm <file>` | ||
| * @param string|string[] | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function removeFile($file) | ||
|
|
@@ -260,11 +264,38 @@ public function removeFile($file) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Clean repo. | ||
| * `git clean` | ||
| * @param bool $cleanDirectories | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove |
||
| * @param bool $force | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function clean($cleanDirectories = true, $force = true) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change all |
||
| { | ||
| $options = null; | ||
| if (!($cleanDirectories === false && $force === false)) { | ||
| $options = '-'; | ||
| if ($force) { | ||
| $options .= 'f'; | ||
| } | ||
| if ($cleanDirectories) { | ||
| $options .= 'd'; | ||
| } | ||
| } | ||
|
|
||
| return $this->begin() | ||
| ->run('git clean', $options) | ||
| ->end(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Adds file(s). | ||
| * `git add <file>` | ||
| * @param string|string[] | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function addFile($file) | ||
|
|
@@ -289,7 +320,7 @@ public function addFile($file) | |
| /** | ||
| * Adds all created, modified & removed files. | ||
| * `git add --all` | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function addAllChanges() | ||
|
|
@@ -305,7 +336,7 @@ public function addAllChanges() | |
| * `git mv <file>` | ||
| * @param string|string[] from: array('from' => 'to', ...) || (from, to) | ||
| * @param string|NULL | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function renameFile($file, $to = NULL) | ||
|
|
@@ -333,7 +364,7 @@ public function renameFile($file, $to = NULL) | |
| * `git commit <params> -m <message>` | ||
| * @param string | ||
| * @param string[] param => value | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| * @return self | ||
| */ | ||
| public function commit($message, $params = NULL) | ||
|
|
@@ -351,11 +382,12 @@ public function commit($message, $params = NULL) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Exists changes? | ||
| * `git status` + magic | ||
| * @return bool | ||
| */ | ||
| /** | ||
| * Exists changes? | ||
| * `git status` + magic | ||
| * @return bool | ||
| * @throws GitException | ||
| */ | ||
| public function hasChanges() | ||
| { | ||
| // Make sure the `git status` gets a refreshed look at the working tree. | ||
|
|
@@ -439,13 +471,14 @@ public function fetch($remote = NULL, array $params = NULL) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Adds new remote repository | ||
| * @param string | ||
| * @param string | ||
| * @param array|NULL | ||
| * @return self | ||
| */ | ||
| /** | ||
| * Adds new remote repository | ||
| * @param string | ||
| * @param string | ||
| * @param array|NULL | ||
| * @return self | ||
| * @throws GitException | ||
| */ | ||
| public function addRemote($name, $url, array $params = NULL) | ||
| { | ||
| return $this->begin() | ||
|
|
@@ -454,12 +487,13 @@ public function addRemote($name, $url, array $params = NULL) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Renames remote repository | ||
| * @param string | ||
| * @param string | ||
| * @return self | ||
| */ | ||
| /** | ||
| * Renames remote repository | ||
| * @param string | ||
| * @param string | ||
| * @return self | ||
| * @throws GitException | ||
| */ | ||
| public function renameRemote($oldName, $newName) | ||
| { | ||
| return $this->begin() | ||
|
|
@@ -468,11 +502,12 @@ public function renameRemote($oldName, $newName) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Removes remote repository | ||
| * @param string | ||
| * @return self | ||
| */ | ||
| /** | ||
| * Removes remote repository | ||
| * @param string | ||
| * @return self | ||
| * @throws GitException | ||
| */ | ||
| public function removeRemote($name) | ||
| { | ||
| return $this->begin() | ||
|
|
@@ -481,13 +516,14 @@ public function removeRemote($name) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Changes remote repository URL | ||
| * @param string | ||
| * @param string | ||
| * @param array|NULL | ||
| * @return self | ||
| */ | ||
| /** | ||
| * Changes remote repository URL | ||
| * @param string | ||
| * @param string | ||
| * @param array|NULL | ||
| * @return self | ||
| * @throws GitException | ||
| */ | ||
| public function setRemoteUrl($name, $url, array $params = NULL) | ||
| { | ||
| return $this->begin() | ||
|
|
@@ -526,11 +562,12 @@ protected function end() | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * @param string | ||
| * @param callback|NULL | ||
| * @return string[]|NULL | ||
| */ | ||
| /** | ||
| * @param string | ||
| * @param callback|NULL | ||
| * @return string[]|NULL | ||
| * @throws GitException | ||
| */ | ||
| protected function extractFromCommand($cmd, $filter = NULL) | ||
| { | ||
| $output = array(); | ||
|
|
@@ -577,7 +614,7 @@ protected function extractFromCommand($cmd, $filter = NULL) | |
| * Runs command. | ||
| * @param string|array | ||
| * @return self | ||
| * @throws Cz\Git\GitException | ||
| * @throws GitException | ||
| */ | ||
| protected function run($cmd/*, $options = NULL*/) | ||
| { | ||
|
|
@@ -665,13 +702,14 @@ public static function init($directory, array $params = NULL) | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Clones GIT repository from $url into $directory | ||
| * @param string | ||
| * @param string|NULL | ||
| * @param array|NULL | ||
| * @return self | ||
| */ | ||
| /** | ||
| * Clones GIT repository from $url into $directory | ||
| * @param string | ||
| * @param string|NULL | ||
| * @param array|NULL | ||
| * @return self | ||
| * @throws GitException | ||
| */ | ||
| public static function cloneRepository($url, $directory = NULL, array $params = NULL) | ||
| { | ||
| if($directory !== NULL && is_dir("$directory/.git")) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix indentation from spaces to tabs.