Skip to content

git-clang-format removes unstaged files #65643

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

Closed
adorostkar opened this issue Sep 7, 2023 · 3 comments · Fixed by #65723 or llvm/llvm-project-release-prs#736
Closed

git-clang-format removes unstaged files #65643

adorostkar opened this issue Sep 7, 2023 · 3 comments · Fixed by #65723 or llvm/llvm-project-release-prs#736

Comments

@adorostkar
Copy link

Hi all,
While running git clang-format I have come to a scenario where the script doesn't work as expected.

How to reproduce

  1. Have staged changes in file A which require reformatting
  2. Have staged changes in file B which don’t require reformatting
  3. Have unstaged changes in file B which are actual changes (let’s say new function)
  4. Run git clang-format --staged

The effect:

  • Unstaged changes in A which is the format change.
  • New changes in file B are deleted. <- this is the wrong behavior

Additional info

  1. The version of the clang-format and the script is 16.0.6
  2. I am running this on MacOs

If the changes that need formatting are staged in B and anything else is not staged in B then the git-clang-format refuses to format and prints a message saying that there are unstaged changes.

@owenca owenca self-assigned this Sep 8, 2023
owenca added a commit to owenca/llvm-project that referenced this issue Sep 8, 2023
When applying format changes to staged files, git-clang-format erroneously
checks out all files in the index and thus may overwrite unstaged changes.

Fixes llvm#65643.
owenca added a commit that referenced this issue Sep 8, 2023
When applying format changes to staged files, git-clang-format
erroneously checks out all files in the index and thus may overwrite
unstaged changes.

Fixes #65643.
@owenca
Copy link
Contributor

owenca commented Oct 16, 2023

/cherry-pick 743659b

@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2023

/branch llvm/llvm-project-release-prs/issue65643

@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2023

/pull-request llvm/llvm-project-release-prs#736

@tru tru moved this from Needs Triage to Needs Review in LLVM Release Status Oct 17, 2023
tru pushed a commit that referenced this issue Oct 17, 2023
When applying format changes to staged files, git-clang-format
erroneously checks out all files in the index and thus may overwrite
unstaged changes.

Fixes #65643.

(cherry picked from commit 743659b)
@tru tru moved this from Needs Review to Done in LLVM Release Status Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment