Ejemplo n.º 1
0
	/**
	 * Options may include:
	 * -   *cwd* Directory from where changes are to be commited
	 * -   *bin* Path to the Git command
	 * -   *message* Message associated to the commit
	 * 
	 * Exemples
	 * 
	 *     PurGit::commit('My message');
	 * 
	 *     PurGit::commit(array('message'=>'My message','cwd'=>$git));
	 * 
	 *     PurGit::commit('My message',array('cwd'=>$git));
	 * 
	 * @param array $options Options used to alter the method behavior
	 * @return boolean Return true on success or false if there was nothing to be commited
	 * 
	 * @param string $message required Message associated to the commit
	 * @param array $options optional All parameters are optional
	 * @return boolean Return true on success or false if there was nothing to be commited
	 */
	public static function commit(){
		$args = PurLang::args(
			func_get_args(),
			array(
				array('options.message'=>'string'),
				array('options'=>'array'),
				array('options.message'=>'string','options'=>'array')
			)
		);
		$args = $args['options'];
		// Note, at some point, we need to improve args
		// so it could handle empty keys
//		print_r(PurLang::args(
//			func_get_args(),
//			array(
//				array('message'=>'string'),
//				array(''=>'array'),
//				array('message'=>'string',''=>'array')
//			)
//		));
		if(empty($args['message'])){
			throw new InvalidArgumentException('No message provided');
		}
		if(empty($args['bin'])){
			$args['bin'] = self::$bin;
		}
		$status = self::status($args);
		if(empty($status['changed_to_be_committed'])){
			return false;
		}
		$command = $args['bin'];
		$command .= ' commit -m "'.str_replace('"','\\"',$args['message']).'"';
		PurCli::exec($command,$args['path']);
	}
Ejemplo n.º 2
0
	/**
	 * Return a sanitized trace.
	 * 
	 * The optional "base" path parameter offer the ability to transform absolute 
	 * paths to relative path when trace paths are located inside the provided path.
	 * 
	 * Internally, it uses the PHP "debug_backtrace" function and they filter the trace
	 * for greater readability.
	 * 
	 * @param string $base[optional]
	 * 
	 * @return array Trace
	 */
	public static function trace(){
		$args = PurLang::args(
			func_get_args(),
			array(
				array(),
				array('base'=>'string'),
				array('trace'=>array('array','NULL')),
				array('trace'=>array('array','NULL'),''=>'array'),
				array('base'=>'string',''=>'array')));
		if(empty($args['trace'])){
			$args['trace'] = debug_backtrace();
		}
		if(empty($args['base'])){
			$args['base'] = '';
		}else{
			$args['base'] .= '/';
		}
		while(list($k,$v) = each($args['trace'])){
			if(!isset($v['file'])){
				unset($args['trace'][$k]);
			}else{
				unset($args['trace'][$k]['object']);
				$args['trace'][$k]['file'] = PurPath::relative($args['base'],$args['trace'][$k]['file']);
				// Some function like ereg don't return the 'args' key
				if(isset($v['args'])){
					while(list($kk,$vv) = each($v['args'])){
						$args['trace'][$k]['args'][$kk] = PurLang::toString($vv);
					}
				}
			}
		}
		reset($args['trace']);
		return array_values($args['trace']); // reindex the array
	}