Skip to content
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

Annotate specific files only #207

Open
vidrascus opened this issue Jul 28, 2020 · 15 comments
Open

Annotate specific files only #207

vidrascus opened this issue Jul 28, 2020 · 15 comments

Comments

@vidrascus
Copy link

vidrascus commented Jul 28, 2020

Hello,
Is it feasible to annotate specific files only?
I need to run the 'annotate' command only for the amended files, before doing a git commit, not always for all files.

@dereuromark
Copy link
Owner

Sure
right now you can already filter it using -f FooBar...

But you could also implement a git diff based run (only files that have been touched) etc.

@dereuromark
Copy link
Owner

The idea is good, feel free to PR a git diff based filtering as e.g. --diff etc

@vidrascus
Copy link
Author

Hi,
The command I need looks like bin/cake annotations all --filter edit, but it will annotate all the 'edit.ctp' files, not only the file I amended.
Also we cannot pass multiple files to the command i.e: files with their paths, separated by a comma.
Could it be possbile to specify the file path instead of searching for the file?

@vidrascus vidrascus reopened this Jul 28, 2020
@dereuromark
Copy link
Owner

Sure
But why not --diff then directly?

@vidrascus
Copy link
Author

vidrascus commented Jul 28, 2020

To have an idea, here is what I currently implemented:

STAGED_FILES=$(git diff --name-only --cached --diff-filter=ACMR HEAD -- '*.php' '*.ctp')

for STAGED_FILE in $STAGED_FILES; do

   FILE_NAME="${STAGED_FILE##*/}"

   bin/cake annotations all --filter ${FILE_NAME%.*}  // file name without path and extension, the way it works

done 

@vidrascus
Copy link
Author

The code above will also annotate the files which have exactly the same name as the amended files.
The goal is to annotate the amended files only.
To achieve that, we need to specify the file paths as well in the annotate command, is that right?

@vidrascus
Copy link
Author

I was expecting to have just one line of code, as it is possible for the php-cs-fixer library:
bin/cake annotations all --filter "$STAGED_FILES"

@vidrascus
Copy link
Author

My current issue is that when I specify the path as well, the file is not found to be annotated.
May I know how could we handle that?

@dereuromark
Copy link
Owner

We could either make --filter smarter, or we use a different --path element to check specific paths only.
Feel free to make a PR and see if that works.

@vidrascus
Copy link
Author

Alright, since we need only specific files (with full paths and extensions) to be annotated, we could check, if the value entered in the --filter, is a file and the file exists, then we just use the value instead of the search for the files (as currently it does).

@vidrascus
Copy link
Author

We could also add the ability to handle multiple files with full paths (separated by a space) i.e:
bin/cake annotations all --filter /path/file1 /path/file2

@dereuromark
Copy link
Owner

instead of space, comma separated might work

@vidrascus
Copy link
Author

Alright, as soon as I do the update, will open a PR

@dereuromark
Copy link
Owner

Did you have a chance to look into this further?

@dereuromark
Copy link
Owner

ping @vidrascus

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