<commit_before><?php
/**
 * Garp_Cli_Command_Git
 * Providing a user-friendly Git interface.
 *
 * @author       $Author:$
 * @modifiedby   $LastChangedBy:$
 * @version      $LastChangedRevision:$
 * @package      Garp
 * @subpackage   Cli
 * @lastmodified $LastChangedDate:$
 */
class Garp_Cli_Command_Git extends Garp_Cli_Command {
	/**
 	 * Setup Git as per Grrr conventions
 	 * @return Void
 	 */
	public function setup() {
		Garp_Cli::lineOut('Configuring Git...');
		// configure core.fileMode
		passthru('git config core.fileMode false');
		// configure color.ui
		passthru('git config color.ui auto');
		// checkout branch master in Garp submodule
		// sanity check: do we have a garp folder?
		if (is_dir('garp')) {
			chdir('garp');
			$branches = `git branch`;                                                               
			$branches = explode("\n", $branches);
			// only checkout master if it's currently not on any branch
			if ($branches[0] == '* (no branch)') {
				passthru('git checkout master');
			}
			// change dir back
			chdir('..');
		}
		
		// setup git hook for updating APP_VERSION
		$hookSource = GARP_APPLICATION_PATH.'/../scripts/util/post-commit';
		$hookTarget = APPLICATION_PATH.'/../.git/hooks/post-commit';
		$performTheMove = true;
		if (file_exists($hookTarget)) {
			// Warn use about existing hook. Might be accidental
			$performTheMove = Garp_Cli::confirm('Post-commit hook already in place. Overwrite?');
		}
		if ($performTheMove) {
			passthru("cp $hookSource $hookTarget");
			// Make hook executable
			passthru("chmod u+x $hookTarget");
		}
		Garp_Cli::lineOut('Done.');
	}


	/**
 	 * Automatically pulls submodules as well.
 	 * @param Array $args No arguments required, passing some will result in error.
 	 * @return Void
 	 */
	public function pull(array $args = array()) {
		if (!empty($args)) {
			Garp_Cli::errorOut('Invalid option: '.$args[0]);
			return false;
		}
		passthru('git pull --recurse-submodules && git submodule foreach git pull');
	}


	/**
 	 * Commit a submodule
 	 * @param Array $args
 	 * @return Void
 	 */
	public function commitSubmodule(array $args = array()) {
		if (empty($args[0])) {
			Garp_Cli::errorOut('Specify submodule as first argument.');
			return false;
		}
		if (empty($args['m'])) {
			Garp_Cli::errorOut('Aborting commit due to empty commit message');<commit_msg>Also add Garp post-commit hook from setup script<commit_after><?php
/**
 * Garp_Cli_Command_Git
 * Providing a user-friendly Git interface.
 *
 * @author       $Author:$
 * @modifiedby   $LastChangedBy:$
 * @version      $LastChangedRevision:$
 * @package      Garp
 * @subpackage   Cli
 * @lastmodified $LastChangedDate:$
 */
class Garp_Cli_Command_Git extends Garp_Cli_Command {
	/**
 	 * Setup Git as per Grrr conventions
 	 * @return Void
 	 */
	public function setup() {
		Garp_Cli::lineOut('Configuring Git...');
		// configure core.fileMode
		passthru('git config core.fileMode false');
		// configure color.ui
		passthru('git config color.ui auto');
		// checkout branch master in Garp submodule
		// sanity check: do we have a garp folder?
		if (is_dir('garp')) {
			chdir('garp');
			$branches = `git branch`;                                                               
			$branches = explode("\n", $branches);
			// only checkout master if it's currently not on any branch
			if ($branches[0] == '* (no branch)') {
				passthru('git checkout master');
			}
			// change dir back
			chdir('..');
		}
		
		// setup git hook for updating APP_VERSION... 
		$hookSource = GARP_APPLICATION_PATH.'/../scripts/util/post-commit';
		$hookTarget = APPLICATION_PATH.'/../.git/hooks/post-commit';
		$this->_moveGitHook($hookSource, $hookTarget);
		// ...and GARP_VERSION
		$hookSource = GARP_APPLICATION_PATH.'/../scripts/util/garp-post-commit';
		$hookTarget = APPLICATION_PATH.'/../garp/.git/hooks/post-commit';
		$this->_moveGitHook($hookSource, $hookTarget);

		Garp_Cli::lineOut('Done.');
	}


	/**
 	 * Move Git Hook into place
 	 * @param String $hookSource Source file
 	 * @param String $hookTarget Target file
 	 * @return Void
 	 */
	protected function _moveGitHook($hookSource, $hookTarget) {
		$performTheMove = true;
		if (file_exists($hookTarget)) {
			// Warn user about existing hook. Might be accidental
			$performTheMove = Garp_Cli::confirm('Hook '.$hookTarget.' already in place. Overwrite?');
		}
		if ($performTheMove) {
			passthru("cp $hookSource $hookTarget");
			// Make hook executable
			passthru("chmod u+x $hookTarget");
		}		
	}


	/**
 	 * Automatically pulls submodules as well.
 	 * @param Array $args No arguments required, passing some will result in error.
 	 * @return Void
 	 */
	public function pull(array $args = array()) {
		if (!empty($args)) {
			Garp_Cli::errorOut('Invalid option: '.$args[0]);
			return false;
		}
		passthru('git pull --recurse-submodules && git submodule foreach git pull');
	}


	/**
 	 * Commit a submodule
 	 * @param Array $args
 	 * @return Void
 	 */
	public function commitSubmodule(array $args = array()) {
		if (empty($args[0])) {
			Garp_Cli::errorOut('Specify submodule as first argument.');
			return false;
		}
		if (empty($args['m'])) {
			Garp_Cli::errorOut('Aborting commit due to empty commit message');
{'fraction_non_alphanumeric': 0.14266666666666666, 'fraction_numerical': 0.001142857142857143, 'mean_word_length': 3.11843137254902, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1762788', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1653, 'n_words': 443}