/** * Warn the user if the working copy has any untracked changes * * @param CommandRunner $cmd_runner cmd runner object * @param string $repo_path location of the git repo * @param string $upstream upstream branch name **/ function check($cmd_runner, $repo_path, $upstream) { $cmd_runner->run('git ls-files --exclude-standard --others'); $output = $cmd_runner->getOutput(); $untracked_files = array_filter(explode(PHP_EOL, $output)); if (!empty($untracked_files)) { $msg = 'You have '; $msg .= count($untracked_files); $msg .= ' untracked files in your working copy' . PHP_EOL; $cmd_runner->warn($msg); } }
/** * Warn the user if the changed files contain any blacklisted files * * @param CommandRunner $cmd_runner cmd runner object * @param string $repo_path location of the git repo * @param string $upstream upstream branch name **/ function check($cmd_runner, $repo_path, $upstream) { $cmd = 'git diff --name-only ' . $upstream; if ($this->staged) { $cmd .= ' --staged'; } if (!empty($this->whitelist)) { $cmd .= ' ' . implode(' ', $this->whitelist); } $cmd_runner->run($cmd); $changed_files = $cmd_runner->getOutput(); $blacklisted_changed_files = array(); foreach (explode(PHP_EOL, $changed_files) as $file) { if (in_array($file, $this->blacklist)) { $blacklisted_changed_files[] = $file; } } if (!empty($blacklisted_changed_files)) { $msg = 'The diff you are trying to submit contains the following blacklisted file(s) : '; $msg .= implode(',', $blacklisted_changed_files); $cmd_runner->warn($msg); } }