@@ -36,7 +36,7 @@ class Git {
3636 * @param string repository path
3737 * @param string directory to source
3838 * @return GitRepo
39- */
39+ */
4040 public static function &create ($ repo_path , $ source = null ) {
4141 return GitRepo::create_new ($ repo_path , $ source );
4242 }
@@ -49,7 +49,7 @@ public static function &create($repo_path, $source = null) {
4949 * @access public
5050 * @param string repository path
5151 * @return GitRepo
52- */
52+ */
5353 public static function open ($ repo_path ) {
5454 return new GitRepo ($ repo_path );
5555 }
@@ -62,11 +62,11 @@ public static function open($repo_path) {
6262 * @access public
6363 * @param mixed variable
6464 * @return bool
65- */
65+ */
6666 public static function is_repo ($ var ) {
6767 return (get_class ($ var ) == 'GitRepo ' );
6868 }
69-
69+
7070}
7171
7272// ------------------------------------------------------------------------
@@ -82,7 +82,7 @@ public static function is_repo($var) {
8282class GitRepo {
8383
8484 protected $ repo_path = null ;
85-
85+
8686 public $ git_path = '/usr/bin/git ' ;
8787
8888 /**
@@ -94,7 +94,7 @@ class GitRepo {
9494 * @param string repository path
9595 * @param string directory to source
9696 * @return GitRepo
97- */
97+ */
9898 public static function &create_new ($ repo_path , $ source = null ) {
9999 if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " ) && is_dir ($ repo_path ."/.git " )) {
100100 throw new Exception ('"$repo_path" is already a git repository ' );
@@ -171,7 +171,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
171171 *
172172 * @access public
173173 * @return bool
174- */
174+ */
175175 public function test_git () {
176176 $ descriptorspec = array (
177177 1 => array ('pipe ' , 'w ' ),
@@ -198,7 +198,7 @@ public function test_git() {
198198 * @access protected
199199 * @param string command to run
200200 * @return string
201- */
201+ */
202202 protected function run_command ($ command ) {
203203 $ descriptorspec = array (
204204 1 => array ('pipe ' , 'w ' ),
@@ -227,7 +227,7 @@ protected function run_command($command) {
227227 * @access public
228228 * @param string command to run
229229 * @return string
230- */
230+ */
231231 public function run ($ command ) {
232232 return $ this ->run_command ($ this ->git_path ." " .$ command );
233233 }
@@ -240,7 +240,7 @@ public function run($command) {
240240 * @access public
241241 * @param mixed files to add
242242 * @return string
243- */
243+ */
244244 public function add ($ files = "* " ) {
245245 if (is_array ($ files )) $ files = '" ' .implode ('" " ' , $ files ).'" ' ;
246246 return $ this ->run ("add $ files -v " );
@@ -254,7 +254,7 @@ public function add($files = "*") {
254254 * @access public
255255 * @param string commit message
256256 * @return string
257- */
257+ */
258258 public function commit ($ message = "" ) {
259259 return $ this ->run ("commit -av -m \"$ message \"" );
260260 }
@@ -268,7 +268,7 @@ public function commit($message = "") {
268268 * @access public
269269 * @param string target directory
270270 * @return string
271- */
271+ */
272272 public function clone_to ($ target ) {
273273 return $ this ->run ("clone --local " .$ this ->repo_path ." $ target " );
274274 }
@@ -282,7 +282,7 @@ public function clone_to($target) {
282282 * @access public
283283 * @param string source directory
284284 * @return string
285- */
285+ */
286286 public function clone_from ($ source ) {
287287 return $ this ->run ("clone --local $ source " .$ this ->repo_path );
288288 }
@@ -296,7 +296,7 @@ public function clone_from($source) {
296296 * @access public
297297 * @param string source url
298298 * @return string
299- */
299+ */
300300 public function clone_remote ($ source ) {
301301 return $ this ->run ("clone $ source " .$ this ->repo_path );
302302 }
@@ -309,7 +309,7 @@ public function clone_remote($source) {
309309 * @access public
310310 * @param bool delete directories?
311311 * @return string
312- */
312+ */
313313 public function clean ($ dirs = false ) {
314314 return $ this ->run ("clean " .(($ dirs ) ? " -d " : "" ));
315315 }
@@ -322,7 +322,7 @@ public function clean($dirs = false) {
322322 * @access public
323323 * @param string branch name
324324 * @return string
325- */
325+ */
326326 public function create_branch ($ branch ) {
327327 return $ this ->run ("branch $ branch " );
328328 }
@@ -335,7 +335,7 @@ public function create_branch($branch) {
335335 * @access public
336336 * @param string branch name
337337 * @return string
338- */
338+ */
339339 public function delete_branch ($ branch , $ force = false ) {
340340 return $ this ->run ("branch " .(($ force ) ? '-D ' : '-d ' )." $ branch " );
341341 }
@@ -384,11 +384,69 @@ public function active_branch($keep_asterisk = false) {
384384 * @access public
385385 * @param string branch name
386386 * @return string
387- */
387+ */
388388 public function checkout ($ branch ) {
389389 return $ this ->run ("checkout $ branch " );
390390 }
391391
392+
393+ /**
394+ * Runs a `git merge` call
395+ *
396+ * Accepts a name for the branch to be merged
397+ *
398+ * @access public
399+ * @param string $branch
400+ * @return string
401+ */
402+ public function merge ($ branch )
403+ {
404+ return $ this ->run ("merge $ branch --no-ff " );
405+ }
406+
407+
408+ /**
409+ * Runs a git fetch on the current branch
410+ *
411+ * @access public
412+ * @return string
413+ */
414+ public function fetch ()
415+ {
416+ return $ this ->run ("fetch " );
417+ }
418+
419+ /**
420+ * Add a new tag on the current position
421+ *
422+ * Accepts the name for the tag and the message
423+ *
424+ * @param string $tag
425+ * @param string $message
426+ * @return string
427+ */
428+ public function add_tag ($ tag , $ message = null )
429+ {
430+ if ($ message === null ) {
431+ $ message = $ tag ;
432+ }
433+ return $ this ->run ("tag -a $ tag -m $ message " );
434+ }
435+
436+
437+ /**
438+ * Push specific branch to a remote
439+ *
440+ * Accepts the name of the remote and local branch
441+ *
442+ * @param string $remote
443+ * @param string $branch
444+ * @return string
445+ */
446+ public function push ($ remote , $ branch )
447+ {
448+ return $ this ->run ("push --tags $ remote $ branch " );
449+ }
392450}
393451
394452/* End Of File */
0 commit comments