[Python] Using pre-commit, how do I know if the user have passed the flag `-a` or...

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    The issue I am having is that I am trying to create a git hook that will do three things

    1. Make sure that the file have the correct header
    2. If the header is correct, check so that the year is correct
    3. If the year is not correct, update the year to current year

    This works fine and I am using pre-commit to start the git hook. However, when I run with the pre-commit flag -a or --all-files, ex pre-commit run -a, every single header is updated to current year. I do not want this so want to add a condition that when -a or --all-files is passed, do not perform step 3.

    The problem is, I do not for the life of me know how to do this. As far as I can see, it is not passed with to the main python function, only the list with files that pre-commit want to run the hook on (which is all the files in this case).

    So, is there a way to know when all files is passed in the hook?

    Continue reading...

Compartilhe esta Página