-
-
Notifications
You must be signed in to change notification settings - Fork 107
Enhancements, improvements... #15
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 |
---|---|---|
|
@@ -25,6 +25,8 @@ public function __construct($repository) | |
if(basename($repository) === '.git') | ||
{ | ||
$repository = dirname($repository); | ||
// Fix ssl errors. | ||
exec('git config --global http.sslVerify false'); | ||
} | ||
|
||
$this->repository = realpath($repository); | ||
|
@@ -351,7 +353,7 @@ public function commit($message, $params = NULL) | |
|
||
|
||
/** | ||
* Exists changes? | ||
* Exists any changes? | ||
* `git status` + magic | ||
* @return bool | ||
*/ | ||
|
@@ -360,19 +362,92 @@ public function hasChanges() | |
$this->begin(); | ||
$lastLine = exec('git status'); | ||
$this->end(); | ||
return (strpos($lastLine, 'nothing to commit')) === FALSE; // FALSE => changes | ||
return ((strpos($lastLine, 'nothing to commit')) || (strpos($lastLine, 'branch is behind'))) === FALSE; | ||
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. This is BC break. Method What is your use-case? In what case is last line "branch is behind"? Can you give a example? Probably better will be new method, something like your suggested |
||
} | ||
|
||
|
||
/** | ||
* Exists local changes? | ||
* `git status` + magic | ||
* @return bool | ||
*/ | ||
public function hasLocalChanges() | ||
{ | ||
$this->begin(); | ||
$lastLine = exec('git status'); | ||
$this->end(); | ||
return !preg_match("/nothing to commit/",$lastLine); | ||
} | ||
|
||
|
||
/** | ||
* @deprecated | ||
* Exists local changes? | ||
* `git status` + magic | ||
* @return bool | ||
*/ | ||
public function isChanges() | ||
public function hasRemoteChanges() | ||
{ | ||
return $this->hasChanges(); | ||
$this->begin(); | ||
exec('git status',$lines); | ||
$this->end(); | ||
return (preg_match("/fast-forwarded/",implode(" ",$lines))); | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* Read Log Messages to JSON | ||
* | ||
* @param string $branch - The branch to read logs from | ||
* @param string|int $limit - Number of commits to return, or the commit hash to return logs until | ||
* @throws Cz\Git\GitException | ||
* @return array $logs | ||
*/ | ||
|
||
public function readLog($branch="origin/master",$limit=10) | ||
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. What about something like |
||
{ | ||
$output = ""; | ||
$this->begin(); | ||
$commits = []; | ||
if (!is_numeric($limit)) { | ||
$command = "git log $limit..$branch --oneline"; | ||
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. Values of |
||
exec($command,$shorts); | ||
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. What if |
||
} | ||
if (count($shorts)) $limit = count($shorts)-1; | ||
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. Undefined variable |
||
if (is_numeric($limit)) { | ||
$i = 0; | ||
do { | ||
$command = "git log $branch -1 --pretty=format:"; | ||
if ($i) $command = "git log $branch --skip $i -1 --pretty=format:"; | ||
$head = exec($command.'"%H"'); | ||
$shortHead = exec($command.'"%h"'); | ||
$subject = exec($command.'"%s"'); | ||
exec($command.'"%b"',$body); | ||
$body = implode('<br>',$body); | ||
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. Use |
||
$author = exec($command.'"%aN"'); | ||
$date = exec($command.'"%aD"'); | ||
$commit = [ | ||
'head'=>$head, | ||
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. Maybe |
||
'shortHead'=>$shortHead, | ||
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. Is |
||
'subject'=>$subject, | ||
'body'=>$body, | ||
'author'=>$author, | ||
'date'=>$date | ||
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. I think better is date in format like |
||
]; | ||
array_push($commits,$commit); | ||
$i++; | ||
} while ($i <= $limit); | ||
} | ||
$this->end(); | ||
return $commits; | ||
} | ||
public function getRev() { | ||
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. Probably better is |
||
$this->begin(); | ||
$head = exec('git rev-parse HEAD'); | ||
$this->end(); | ||
return $head; | ||
} | ||
/** | ||
* Pull changes from a remote | ||
* @param string|NULL | ||
|
@@ -387,9 +462,10 @@ public function pull($remote = NULL, array $params = NULL) | |
$params = array(); | ||
} | ||
|
||
return $this->begin() | ||
->run("git pull $remote", $params) | ||
->end(); | ||
$this->begin(); | ||
$result = $this->run("git pull $remote", $params); | ||
$this->end(); | ||
return $result; | ||
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. It's BC break. Why you need |
||
} | ||
|
||
|
||
|
@@ -427,9 +503,10 @@ public function fetch($remote = NULL, array $params = NULL) | |
$params = array(); | ||
} | ||
|
||
return $this->begin() | ||
->run("git fetch $remote", $params) | ||
->end(); | ||
$this->begin(); | ||
$result = $this->run("git fetch $remote", $params); | ||
$this->end(); | ||
return $result; | ||
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. It's BC break. Why you need |
||
} | ||
|
||
|
||
|
@@ -579,12 +656,13 @@ protected function run($cmd/*, $options = NULL*/) | |
$cmd = self::processCommand($args); | ||
exec($cmd . ' 2>&1', $output, $ret); | ||
|
||
$result = implode (" ",$output); | ||
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. This is BC break. |
||
if($ret !== 0) | ||
{ | ||
throw new GitException("Command '$cmd' failed (exit-code $ret).", $ret); | ||
$result = "Command '$cmd' failed (exit-code $ret): $ret"; | ||
} | ||
|
||
return $this; | ||
return $result; | ||
} | ||
|
||
|
||
|
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.
This is bad practise, SSL verify is usefull. Right way is fix SSL issue on server. Alternatively you can extends class
GitRepository
and change constructor in your code base: