3

I'm running Ubuntu on WSL2 and VSCode on top of that. Although I have the "LF" setting on VSCode, whenever I save the file, VSCode insists on inserting a carriage return that gets marked as ^M with git diff. Check it out:

diff --git a/network/outputs.tf b/network/outputs.tf
index e13366b..f7cc29c 100644
--- a/network/outputs.tf
+++ b/network/outputs.tf
@@ -1,4 +1,4 @@
-output "vpc_id" {
-    description = "The ID of the Main VPC"
-    value       = aws_vpc.main.id
+output "vpc_id" {^M
+    description = "The ID of the Main VPC"^M
+    value       = aws_vpc.main.id^M
 }

I have no problem with this on VIM.

adriaanbd
  • 317
  • 4
  • 12
  • Have you installed VSCode inside WSL or on Windows ? – Philippe Oct 29 '20 at 20:44
  • @Philippe To be honest, I don't remember exactly. What would be the best approach? I'm willing to uninstall and re-install to put an end to it. – adriaanbd Oct 29 '20 at 20:56
  • 1
    I tend to install on Windows. Anyway, on git side, run `git config --list` and make sure `core.autocrlf=false` – Philippe Oct 29 '20 at 21:45
  • @Philippe Thanks for your help, I've applied this config to global setting but unfortunately that wasn't enough to solve the issue, it still inserts a carriage return. – adriaanbd Oct 30 '20 at 17:57
  • 1
    Can you do `dos2unix network/outputs.tf`, then use VSCode to edit and save it, then do `git diff` again ? – Philippe Oct 30 '20 at 18:06
  • @Philippe yes that worked, it no longer has the `^M` mark – adriaanbd Oct 30 '20 at 19:36
  • It proves that VSCode does not introduce ^M. Can you do this test : commit the file, remove the file from directory, then checkout, to see if it still has ^M ? – Philippe Oct 30 '20 at 20:06

1 Answers1

0

If git config --global core.autocrlf=false is not enough, check if there is a .gitattributes rule (typically core.eol) which could influence how Git commit the file:

git check-attr --all -- network/outputs.tf
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. I did this and still persisted. The `dox2unix` does the work, but looking for something that does it automatically. – adriaanbd Oct 30 '20 at 20:03
  • 1
    @adriaanbd if that persists, it would be in your interest to dos2unix all the files, add, commit, and then checkout again to check that everything stays as is. – VonC Oct 30 '20 at 20:16