<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107017>107017</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [v18.1.8] clang-format: git integration doesn't work on Windows if the install path contains spaces
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jeliebig
      </td>
    </tr>
</table>

<pre>
    Currently the git integration for clang-format doesn't work on Windows if LLVM was installed to a path which contains spaces (like `C:/Program Files/LLVM` for example`).

This can be verified by either executing `git-clang-format` from cmd or using a simple pre-commit hook which executes `git clang-format`:
![image](https://github.com/user-attachments/assets/cd77c44c-127d-471f-b86d-d50a250749f5)

Example `pre-commit` hook:

```sh
#!/bin/sh

exec git clang-format -v
```

The actual script that gets executed in the end is located at `C:/Program Files/LLVM/bin/git-clang-format.bat` and contains the following code:

```bat
py -3 %~pn0 %*
```

I needed to look up what the modifiers `~pn` were actually doing, but after finding [this helpful website](https://ss64.com/nt/syntax-args.html) it turns out we only need to add some quotes around the first argument to fix this issue.

The usage of `~` expands the argument, but also removes any surrounding quotes, so we need to add them back manually.

The fixed script looks like this:

```bat
py -3 "%~pn0" %*
```

![image](https://github.com/user-attachments/assets/aea95a1b-0f5f-4b6d-8526-cf4931639e52)

---

I have never contributed to LLVM before and don't have enough time to fix this issue myself even though it's an easy one.  
I hope my bug report can get this issue fixed regardless.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU-P27YT_TT0ZSBBov7ZBx-S7M_AD0iBHor2TJEjiVmKVMmRvb7ksxek7Oyu0yY9FFhQa4KceW_e44wIQY8W8ciaj6x52omVJuePX9Bo7PW46526Hj-t3qMlcwWaEEZNoC3h6AVpZ2FwHqQRdswG52dBoBwGy3hHcHH-GZyFP7RV7hJAD_D58--_wEUE0DaQMAYVkAMBi6A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