pretty-quick icon indicating copy to clipboard operation
pretty-quick copied to clipboard

`pretty-quick --staged` in pre-commit has odd behavior in conjunction with `git commit PATH…`

Open nelhage opened this issue 4 years ago • 0 comments

If I have pretty-quick --staged as a pre-commit hook, and I commit some files directly, I get a weird state where the commit and the working tree end up with the formatted files, but the index still has the old, unformatted files.

Starting from https://github.com/nelhage/pretty-quick-bugreport, we can see this as follows:

[nelhage@monolithique:~/code/pretty-quick-repro]$ echo $'function f( a,  b) {}' >> main.js 
[nelhage@monolithique:~/code/pretty-quick-repro]$ git ci main.js -m 'testing'                                          
🔍  Finding changed files since git revision 41b9102.   
🎯  Found 1 changed file.                  
✍  Fixing up main.js.                                                                                                  
  EvEverythingsiswawesome!   s                                                                                         
[master 8601415] testing                     
 1 file changed, 1 insertion(+)                                                                                        
[nelhage@monolithique:~/code/pretty-quick-repro]$ git --no-pager diff HEAD
[nelhage@monolithique:~/code/pretty-quick-repro]$ git --no-pager diff 
diff --git a/main.js b/main.js
index 56ddb1c..f3cb734 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,4 @@
 function testFunc(a, b) {
   return a + b;
 }
-function f( a,  b) {}
+function f(a, b) {}
[nelhage@monolithique:~/code/pretty-quick-repro]$ git --no-pager diff --cached 
diff --git a/main.js b/main.js
index f3cb734..56ddb1c 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,4 @@
 function testFunc(a, b) {
   return a + b;
 }
-function f(a, b) {}
+function f( a,  b) {}
[nelhage@monolithique:~/code/pretty-quick-repro]$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   main.js

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   main.js

nelhage avatar Feb 19 '21 01:02 nelhage