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

[clang-format] Fix a bug in git-clang-format --binary #74176

Merged
merged 1 commit into from
Dec 3, 2023

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Dec 2, 2023

Fixed #74165.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 2, 2023

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fixed #74165.


Full diff: https://github.com/llvm/llvm-project/pull/74176.diff

1 Files Affected:

  • (modified) clang/tools/clang-format/git-clang-format (+1)
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 0f33b5339ec14cb..6e827e17b4ee291 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -153,6 +153,7 @@ def main():
   else:
     if len(commits) > 2:
       die('at most two commits allowed; %d given' % len(commits))
+  opts.binary=os.path.abspath(opts.binary)
   changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
     ignored_files = set(changed_lines)

@owenca owenca merged commit 2a3f119 into llvm:main Dec 3, 2023
4 checks passed
@owenca owenca deleted the git-clang-format branch December 3, 2023 10:07
@JOE1994
Copy link
Member

JOE1994 commented Dec 4, 2023

I've been using git clang-format without the --bin flag using the following setting

  1. PATH=$PATH:~/llvm-project/build/bin:~/llvm-project/clang/tools/clang-format
  2. Run git clang-format HEAD~1 at ~/llvm-project directory

After this revision, I get the following error:

error: cannot find executable "<FULL_PATH_UP_TO_LLVM_PROJECT>/llvm-project/clang-format"

(<FULL_PATH_UP_TO_LLVM_PROJECT> = full path to the parent directory of llvm-project directory)

owenca added a commit to owenca/llvm-project that referenced this pull request Dec 4, 2023
owenca added a commit that referenced this pull request Dec 4, 2023
This is a rework of #74176, which erroneously changed the default
clang-format filename (`clang-format`, `clang-format.exe`, etc.) to an
absolute pathname. Instead, we should do that only if the name is a
pathname, e.g. `./clang-format`,
`llvm-project/build/bin/clang-format.exe`, etc. See also
#74176 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git clang-format --binary does not always work
4 participants