Skip to content

Commit 4212330

Browse files
committed
reformated code
1 parent b2c9a1c commit 4212330

File tree

2 files changed

+179
-141
lines changed

2 files changed

+179
-141
lines changed

CI_Git.php

Lines changed: 111 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*
66
* An open source application development framework for PHP 4.3.2 or newer
77
*
8-
* @package CodeIgniter
9-
* @author ExpressionEngine Dev Team
10-
* @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
11-
* @license http://codeigniter.com/user_guide/license.html
12-
* @link http://codeigniter.com
13-
* @since Version 1.0
8+
* @package CodeIgniter
9+
* @author ExpressionEngine Dev Team
10+
* @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
11+
* @license http://codeigniter.com/user_guide/license.html
12+
* @link http://codeigniter.com
13+
* @since Version 1.0
1414
* @filesource
1515
*/
1616

@@ -22,11 +22,11 @@
2222
* This class enables the creating, reading, and manipulation
2323
* of git repositories.
2424
*
25-
* @package CodeIgniter
26-
* @subpackage Git.php
27-
* @category Libraries
28-
* @author James Brumond
29-
* @link http://code.kbjrweb.com/project/gitphp
25+
* @package CodeIgniter
26+
* @subpackage Git.php
27+
* @category Libraries
28+
* @author James Brumond
29+
* @link http://code.kbjrweb.com/project/gitphp
3030
*/
3131
class Git {
3232

@@ -35,10 +35,10 @@ class Git {
3535
*
3636
* Accepts a creation path, and, optionally, a source path
3737
*
38-
* @access public
39-
* @param string repository path
40-
* @param string directory to source
41-
* @return GitRepo
38+
* @access public
39+
* @param string repository path
40+
* @param string directory to source
41+
* @return GitRepo
4242
*/
4343
public function &create($repo_path, $source = null) {
4444
return GitRepo::create_new($repo_path, $source);
@@ -49,9 +49,9 @@ public function &create($repo_path, $source = null) {
4949
*
5050
* Accepts a repository path
5151
*
52-
* @access public
53-
* @param string repository path
54-
* @return GitRepo
52+
* @access public
53+
* @param string repository path
54+
* @return GitRepo
5555
*/
5656
public function open($repo_path) {
5757
return new GitRepo($repo_path);
@@ -62,9 +62,9 @@ public function open($repo_path) {
6262
*
6363
* Accepts a variable
6464
*
65-
* @access public
66-
* @param mixed variable
67-
* @return bool
65+
* @access public
66+
* @param mixed variable
67+
* @return bool
6868
*/
6969
public static function is_repo($var) {
7070
return (get_class($var) == 'GitRepo');
@@ -80,11 +80,11 @@ public static function is_repo($var) {
8080
* This class enables the creating, reading, and manipulation
8181
* of a git repository
8282
*
83-
* @package CodeIgniter
84-
* @subpackage CIGit
85-
* @category Libraries
86-
* @author James Brumond
87-
* @link http://code.kbjrweb.com/project/gitphp
83+
* @package CodeIgniter
84+
* @subpackage CIGit
85+
* @category Libraries
86+
* @author James Brumond
87+
* @link http://code.kbjrweb.com/project/gitphp
8888
*/
8989
class GitRepo {
9090

@@ -97,10 +97,10 @@ class GitRepo {
9797
*
9898
* Accepts a creation path, and, optionally, a source path
9999
*
100-
* @access public
101-
* @param string repository path
102-
* @param string directory to source
103-
* @return GitRepo
100+
* @access public
101+
* @param string repository path
102+
* @param string directory to source
103+
* @return GitRepo
104104
*/
105105
public static function &create_new($repo_path, $source = null) {
106106
if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
@@ -119,10 +119,10 @@ public static function &create_new($repo_path, $source = null) {
119119
*
120120
* Accepts a repository path
121121
*
122-
* @access public
123-
* @param string repository path
124-
* @param bool create if not exists?
125-
* @return void
122+
* @access public
123+
* @param string repository path
124+
* @param bool create if not exists?
125+
* @return void
126126
*/
127127
public function __construct($repo_path = null, $create_new = false, $_init = true) {
128128
if (is_string($repo_path))
@@ -134,10 +134,10 @@ public function __construct($repo_path = null, $create_new = false, $_init = tru
134134
*
135135
* Accepts the repository path
136136
*
137-
* @access public
138-
* @param string repository path
139-
* @param bool create if not exists?
140-
* @return void
137+
* @access public
138+
* @param string repository path
139+
* @param bool create if not exists?
140+
* @return void
141141
*/
142142
public function set_repo_path($repo_path, $create_new = false, $_init = true) {
143143
if (is_string($repo_path)) {
@@ -176,8 +176,8 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
176176
/**
177177
* Tests if git is installed
178178
*
179-
* @access public
180-
* @return bool
179+
* @access public
180+
* @return bool
181181
*/
182182
public function test_git() {
183183
$descriptorspec = array(
@@ -202,9 +202,9 @@ public function test_git() {
202202
*
203203
* Accepts a shell command to run
204204
*
205-
* @access protected
206-
* @param string command to run
207-
* @return string
205+
* @access protected
206+
* @param string command to run
207+
* @return string
208208
*/
209209
protected function run_command($command) {
210210
$descriptorspec = array(
@@ -231,9 +231,9 @@ protected function run_command($command) {
231231
*
232232
* Accepts a git command to run
233233
*
234-
* @access public
235-
* @param string command to run
236-
* @return string
234+
* @access public
235+
* @param string command to run
236+
* @return string
237237
*/
238238
public function run($command) {
239239
return $this->run_command($this->git_path." ".$command);
@@ -244,9 +244,9 @@ public function run($command) {
244244
*
245245
* Accepts a list of files to add
246246
*
247-
* @access public
248-
* @param mixed files to add
249-
* @return string
247+
* @access public
248+
* @param mixed files to add
249+
* @return string
250250
*/
251251
public function add($files = "*") {
252252
if (is_array($files)) $files = '"'.implode('" "', $files).'"';
@@ -258,9 +258,9 @@ public function add($files = "*") {
258258
*
259259
* Accepts a commit message string
260260
*
261-
* @access public
262-
* @param string commit message
263-
* @return string
261+
* @access public
262+
* @param string commit message
263+
* @return string
264264
*/
265265
public function commit($message = "") {
266266
return $this->run("commit -av -m \"$message\"");
@@ -272,9 +272,9 @@ public function commit($message = "") {
272272
*
273273
* Accepts a target directory
274274
*
275-
* @access public
276-
* @param string target directory
277-
* @return string
275+
* @access public
276+
* @param string target directory
277+
* @return string
278278
*/
279279
public function clone_to($target) {
280280
return $this->run("clone --local ".$this->repo_path." $target");
@@ -286,9 +286,9 @@ public function clone_to($target) {
286286
*
287287
* Accepts a source directory
288288
*
289-
* @access public
290-
* @param string source directory
291-
* @return string
289+
* @access public
290+
* @param string source directory
291+
* @return string
292292
*/
293293
public function clone_from($source) {
294294
return $this->run("clone --local $source ".$this->repo_path);
@@ -300,9 +300,9 @@ public function clone_from($source) {
300300
*
301301
* Accepts a source url
302302
*
303-
* @access public
304-
* @param string source url
305-
* @return string
303+
* @access public
304+
* @param string source url
305+
* @return string
306306
*/
307307
public function clone_remote($source) {
308308
return $this->run("clone $source ".$this->repo_path);
@@ -313,9 +313,9 @@ public function clone_remote($source) {
313313
*
314314
* Accepts a remove directories flag
315315
*
316-
* @access public
317-
* @param bool delete directories?
318-
* @return string
316+
* @access public
317+
* @param bool delete directories?
318+
* @return string
319319
*/
320320
public function clean($dirs = false) {
321321
return $this->run("clean".(($dirs) ? " -d" : ""));
@@ -326,9 +326,9 @@ public function clean($dirs = false) {
326326
*
327327
* Accepts a name for the branch
328328
*
329-
* @access public
330-
* @param string branch name
331-
* @return string
329+
* @access public
330+
* @param string branch name
331+
* @return string
332332
*/
333333
public function create_branch($branch) {
334334
return $this->run("branch $branch");
@@ -339,27 +339,64 @@ public function create_branch($branch) {
339339
*
340340
* Accepts a name for the branch
341341
*
342-
* @access public
343-
* @param string branch name
344-
* @return string
342+
* @access public
343+
* @param string branch name
344+
* @return string
345345
*/
346346
public function delete_branch($branch, $force = false) {
347347
return $this->run("branch ".(($force) ? '-D' : '-d')." $branch");
348348
}
349349

350+
/**
351+
* Runs a `git branch` call
352+
*
353+
* @access public
354+
* @param bool keep asterisk mark on active branch
355+
* @return array
356+
*/
357+
public function list_branches($keep_asterisk = false) {
358+
$branchArray = explode("\n", $this->run("branch"));
359+
foreach($branchArray as $i => &$branch) {
360+
$branch = trim($branch);
361+
if (! $keep_asterisk)
362+
$branch = str_replace("* ", "", $branch);
363+
if ($branch == "")
364+
unset($branchArray[$i]);
365+
}
366+
return $branchArray;
367+
}
368+
369+
/**
370+
* Returns name of active branch
371+
*
372+
* @access public
373+
* @param bool keep asterisk mark on branch name
374+
* @return string
375+
*/
376+
public function active_branch($keep_asterisk = false) {
377+
$branchArray = $this->list_branches(true);
378+
$active_branch = preg_grep("/^\*/", $branchArray);
379+
reset($active_branch);
380+
if ($keep_asterisk)
381+
return current($active_branch);
382+
else
383+
return str_replace("* ", "", current($active_branch));
384+
}
385+
350386
/**
351387
* Runs a `git checkout` call
352388
*
353389
* Accepts a name for the branch
354390
*
355-
* @access public
356-
* @param string branch name
357-
* @return string
391+
* @access public
392+
* @param string branch name
393+
* @return string
358394
*/
359395
public function checkout($branch) {
360396
return $this->run("checkout $branch");
361397
}
362398

363399
}
364400

365-
/* End Of File */
401+
/* End of file CI_Git.php */
402+
/* Location: ./application/libraries/CI_Git.php */

0 commit comments

Comments
 (0)