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

How to run on all files in a repository? #96

Open
Avasam opened this issue Mar 25, 2024 · 3 comments
Open

How to run on all files in a repository? #96

Avasam opened this issue Mar 25, 2024 · 3 comments

Comments

@Avasam
Copy link

Avasam commented Mar 25, 2024

The pre-commit configuration works fine:

  - repo: https://github.com/pre-commit/mirrors-clang-format
    rev: "v18.1.2"
    hooks:
      - id: clang-format
        # Supports a lot more filetypes, but only tagging those we use
        # https://github.com/pre-commit/mirrors-clang-format/blob/main/.pre-commit-hooks.yaml#L6
        types: [file]
        files: ".*\\.(cpp|cxx|h)"

pre-commit run --all

But I'd like to have this as a github action as well. Running locally, I try pipx run clang-format --dry-run **/*.h **/*.cpp and it gives the following output:

⚠️  clang-format is already on your PATH and installed at C:\Program Files\Python39\Scripts\clang-format.EXE. Downloading and running anyway.
invalid argument
invalid argument

I also tried to pass all the files in (powershell):

clang-format --dry-run $(git ls-files '*.cpp' '*.cxx' "*.h")

But that just resulted in

ResourceUnavailable: Program 'clang-format.exe' failed to run: An error occurred trying to start process 'C:\Program Files\Python39\Scripts\clang-format.exe' with working directory 'E:\Users\Avasam\Documents\Git\pywin32'. The filename or extension is too long.At line:1 char:1
+ clang-format --dry-run $files
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
@dokempf
Copy link
Member

dokempf commented Apr 4, 2024

Can you please check whether there is a difference between 18.1.1 and 18.1.2 for this? We recently changed the inner workings of our packaging and I would like to know whether this is related to that change.

@Avasam
Copy link
Author

Avasam commented May 28, 2024

Hi, 18.1.1 gives me the same results as 18.1.2 and 18.1.5. It doesn't seem like there's support for some sort of include/exclude globbing. Hence I'm currently having to resort to git commands to get the files I want:

- run: | # Too many files to fit in a single command, exclude vendored Scintilla and mapi_headers
    clang-format --Werror --dry-run $(git ls-files '*.cpp')
    clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/mapi_headers/')

@ahrnbom
Copy link

ahrnbom commented Oct 8, 2024

Old issue, but if you still need help with this, you can try something like
find /path/to/repo -iname "*.h" -o -iname "*.cpp" | xargs clang-format -i

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

No branches or pull requests

3 participants