Skip to content

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

@Gormartsen

Description

@Gormartsen

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions