Skip to content

Implement --git-commit-id command option #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Gormartsen opened this issue Aug 2, 2015 · 0 comments
Open

Implement --git-commit-id command option #1

Gormartsen opened this issue Aug 2, 2015 · 0 comments

Comments

@Gormartsen
Copy link
Member

Check my implementation first:

squizlabs/PHP_CodeSniffer@master...itpatrol:master

Comments about code.

This code update after each loop a file and then recollect line numbers changed by last commit and Sniff reports.

It helps to create diff file related only to commit.

Your task is to create command line option to pass commit->id
So instead of

if($reportSha = getenv('SHA')) {
  if(!in_array($line, $this->_process_selected_lines)){
    return false;
....

should be something like

$cliValues = $phpcs->cli->getCommandLineValues();
if (isset($cliValues['got-commit-id']) === true) {
  if(!in_array($line, $this->_process_selected_lines)){
    return false;

Next code, probably, need to be replaced on PHP parsing base instead of grep and awk.
For multi OS compatibility.

exec('git annotate -lt ' . $this->_file. "|grep -E '" . $reportSha . "|0000000000000000000000000000000000000000' |awk -F $'\t' '{print$4}'|awk -F\) '{print$1}'", $this->_process_selected_lines);

Please add verification if current folder is git repository when --git-commit-id provided.
return error if it is not git repo and value provided.

Please make sure that code pass PHPCS code Standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants