[clang] [clang-format] Fix a serious bug in git-clang-format (PR #65723)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 14:56:48 PDT 2023


https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/65723:

>From cf7cca96897d392fcc9bef85c534261afb372d30 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Fri, 8 Sep 2023 01:16:33 -0700
Subject: [PATCH] [clang-format] Fix a serious bug in git-clang-format

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.
---
 clang/tools/clang-format/git-clang-format | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index c0b99b82203234c..0f33b5339ec14cb 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -606,7 +606,7 @@ def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
     index_tree = old_tree
   else:
     with temporary_index_file(new_tree):
-      run('git', 'checkout-index', '-a', '-f')
+      run('git', 'checkout-index', '-f', '--', *changed_files)
   return changed_files
 
 



More information about the cfe-commits mailing list