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

file-contents-sorter doesn't use consistent order with --ignore-case option #1105

Closed
alexdewar opened this issue Oct 31, 2024 · 3 comments
Closed

Comments

@alexdewar
Copy link

I'm trying to use file-contents-sorter to keep a dictionary file sorted, ignoring case. The hook runs fine and updates the file, but when I attempt to commit the changes, it resorts the file again, moving around some entries which differ only in case. If I try to commit those changes, the process repeats.

@asottile
Copy link
Member

works fine for me? please show an actual reproduction

@007
Copy link

007 commented Jan 8, 2025

If lines differ only in case and you specify case-insensitive sorting the results are non-idempotent.

$ cat wtf.wtf
AAA
bbb
BbB
ccc

Then file-contents-sorter with --ignore-case on that file, run 10 times in a row:

$ for x in $(seq 10); do pre-commit run --all;git diff wtf.wtf;done

file contents sorter.....................................................Passed
file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc
file contents sorter.....................................................Passed
diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc
file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc
file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc
file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting wtf.wtf

diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc
file contents sorter.....................................................Passed
diff --git i/wtf.wtf w/wtf.wtf
index 76baeb04f9029d8c..ce2c79e355ff977d 100644
--- i/wtf.wtf
+++ w/wtf.wtf
@@ -1,4 +1,4 @@
 AAA
-bbb
 BbB
+bbb
 ccc

@asottile
Copy link
Member

asottile commented Jan 8, 2025

then that's a dupe of #794

@asottile asottile closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants