- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - 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
          
     Open
      
      
            moay
  wants to merge
  3
  commits into
  czproject:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
moay:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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")) | ||
| 
          
            
          
           | 
    ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.