-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-format] convert path to Windows path if user is using a MSYS2 shell #111526
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
base: main
Are you sure you want to change the base?
Conversation
…shell Currently, we simply rely on the result of `git rev-parse --show-toplevel` in `cd_to_toplevel()`, which when using MSYS2 shell under Windows, can result getting a UNIX path instead of Windows path, and `os.chdir(toplevel)` would simply fail. This patch detects if user is using MSYS2 shell (by checking MSYSTEM environment variable and checking if `cygpath` exists) and will use `cygpath` to convert the path to Windows path.
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang-format Author: Gary Wang (BLumia) ChangesCurrently, we simply rely on the result of This patch detects if user is using MSYS2 shell (by checking Full diff: https://github.com/llvm/llvm-project/pull/111526.diff 1 Files Affected:
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index bacbd8de245666..3424822ede3835 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -31,6 +31,7 @@ import os
import re
import subprocess
import sys
+import shutil
usage = ('git clang-format [OPTIONS] [<commit>] [<commit>|--staged] '
'[--] [<file>...]')
@@ -413,6 +414,8 @@ def filter_ignored_files(dictionary, binary):
def cd_to_toplevel():
"""Change to the top level of the git repository."""
toplevel = run('git', 'rev-parse', '--show-toplevel')
+ if "MSYSTEM" in os.environ and shutil.which('cygpath') is not None:
+ toplevel = run('cygpath', '-w', toplevel)
os.chdir(toplevel)
|
|
I personally use Cygwin and it's git understands unix paths is that not the case for msys2 or are you mixing msys2 with windows based git, won't this have the potential to break others? |
|
Can you please log an issue for this to show what you see and a reproducer |
Git can understand (and will return a) unix path, but it seems MSYS2's python won't accept unix path. It fails at
I guess no: Gary@legion-laptop ~/Source/elisa % which python
/ucrt64/bin/python
Gary@legion-laptop ~/Source/elisa % which git
/usr/bin/git
See msys2/MINGW-packages#2457, simply starting a MSYS2 shell (if using Windows Terminal, you can use something like |
|
@mydeveloperday any update on this? Do I still need to create a new issue in this repo or provide any additional information? |
|
Ping |
|
I'd appreciate this fix, too. |
|
@HazardyKnusperkeks @owenca @cor3ntin sorry for the ping, kindly asking for a review. Thanks in advance! |
|
Would it not be be better to transform the result to a windows path, such as with |
Isn't this a Python/MSYS2 bug? Is it related to #114078? |
I'm not sure if it should be considered as a MSYS2 bug. IMO it should be expected that
Sort of, but #114078 won't fix this issue since MSYS2's shell will invoke |
I also created a discussion thread, see: msys2/MSYS2-packages#4982 |
Currently, we simply rely on the result of
git rev-parse --show-toplevelincd_to_toplevel(), which when using MSYS2 shell under Windows, can result getting a UNIX path instead of Windows path, andos.chdir(toplevel)would simply fail.This patch detects if user is using MSYS2 shell (by checking
MSYSTEMenvironment variable and checking ifcygpathexists) and will usecygpathto convert the path to Windows path.