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

Git: "Stage selected ranges" command changes encoding to UTF-8 #36219

Closed
kav137 opened this issue Oct 13, 2017 · 12 comments
Closed

Git: "Stage selected ranges" command changes encoding to UTF-8 #36219

kav137 opened this issue Oct 13, 2017 · 12 comments
Assignees
Labels
Milestone

Comments

@kav137
Copy link

@kav137 kav137 commented Oct 13, 2017

  • VSCode Version: 1.17.1
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create file with non UTF-8 (UTF-8 with BOM for example) encoding
  2. Commit it
  3. Make some changes
  4. Open VScode's diff view
  5. Select some range and run command "Git: Stage Selected Ranges"
  6. Check encoding of the staged file

Expected result: initial encoding preserved
Actual result: encoding is set to UTF-8

Reproduces without extensions: Yes

Note: "files.encoding" and "files.autoGuessEncoding" settings of VScode doesn't affect anyhow on the result.

@vscodebot vscodebot bot added the new release label Oct 13, 2017
@vscodebot vscodebot bot added the git label Oct 13, 2017
@joaomoreno joaomoreno added bug and removed new release labels Oct 16, 2017
@harimambura

This comment has been minimized.

Copy link

@harimambura harimambura commented Nov 8, 2017

I have the same problem on VSCode Version: 1.18.0 - Insider, OS Version: Windows 10 and this problem also reproduces without extentions. As the my project requires only one file encoding, that's very uncomfortable for me to stage and commit file ranges using external programs like source tree.
Please take a look on this problem

@amitdey1987

This comment has been minimized.

Copy link

@amitdey1987 amitdey1987 commented Feb 8, 2018

if this bug is up for grabs, can I take this up?

@amitdey1987

This comment has been minimized.

Copy link

@amitdey1987 amitdey1987 commented Feb 9, 2018

As @kav137 describes, how can I"Check encoding of the staged file"?

These are the steps I performed

  1. created a file with encoding "UTF8 With Bom", within my repo.
  2. committed this file
  3. using vs code, edited this file
  4. under the "Source Control" tab, I selected this file
  5. ran the command "Git: Stage Selected Ranges"
  6. under the "Source Control" tab, Under the "Staged Changes" section, I select my file.

After this, I am unsure where to look for encoding of the file.
At the bottom-right of the vs code window, I see "Line 1, Col 1 Spaces: 4 Plain Text". But no mention of encoding.

@harimambura

This comment has been minimized.

Copy link

@harimambura harimambura commented Feb 9, 2018

@amitdey1987
I recorded the video which shows how you can reproduce this issue

https://youtu.be/t-ZLTPcUISs

@lorenzo-arena

This comment has been minimized.

Copy link

@lorenzo-arena lorenzo-arena commented May 17, 2018

Are there any news about this? I am working on a Windows-1252 file and using "Stage Selected Ranges" tries to read it UTF-8 (using git add --patch works correctly)

@userFromHades

This comment has been minimized.

Copy link

@userFromHades userFromHades commented Sep 18, 2018

1.27.2 it looks like it's still broken.

@joaomoreno joaomoreno changed the title "Stage selected ranges" command changes encoding to UTF-8 (without regarding to the initial file encoding) Git: "Stage selected ranges" command changes encoding to UTF-8 Sep 18, 2018
@felipecaputo

This comment has been minimized.

Copy link

@felipecaputo felipecaputo commented Oct 29, 2018

I'm looking at this right now, it seems that is because it creates a new document to receive the changes, and the new document doen't refer to any encoding.

I'll need to find how to find the encoding from the current opened document to use the same to the newly created document.

As soon as I find something, I'll let you know

@rysavyjan

This comment has been minimized.

Copy link

@rysavyjan rysavyjan commented Apr 24, 2019

Unfortunately Stage Selected Ranges is unusable because of this problem. Our files are in UTF-8-BOM format and Stage Selected Ranges command strips BOM.

Are we waiting for #55110?

@rysavyjan

This comment has been minimized.

Copy link

@rysavyjan rysavyjan commented May 16, 2019

So I installed OSS Dev version of VSCode and fired debugger. The problem is in vscode\extensions\git\src\git.ts

async stage(path: string, data: string): Promise<void> {
		const child = this.stream(['hash-object', '--stdin', '-w', '--path', path], { stdio: [null, null, null] });
		child.stdin.end(data, 'utf8');

child.stdin.end() is always called with 'utf8', regardless of original file encoding.

Object is staged using git.exe hash-object --stdin -w --path test.cpp

@joaomoreno can you please give me some hint how to continue? Is original file encoding (including BOM/non-BOM information) available here? Thank you. I would really like to fix this problem, so we can use VSCode for interactive staging.

@KUGA2

This comment has been minimized.

Copy link

@KUGA2 KUGA2 commented Jul 30, 2019

Problem is still occurring in 1.36.1.

@rysavyjan: can we just omit the encoding in this call?

@rafaelgssa

This comment has been minimized.

Copy link

@rafaelgssa rafaelgssa commented Sep 29, 2019

This is an annoying issue, because when you go to view the changes on GitHub, it appears as if the entire file was modified, so you can't see what exactly changed. I'll have to keep using git add -p until this is fixed.

@joaomoreno

This comment has been minimized.

Copy link
Member

@joaomoreno joaomoreno commented Nov 20, 2019

This has been fixed thanks to #55110

Verification:

  1. Create a UTF16 file, add some text and commit it
  2. Make another change in the same file and open diff view

Current stable (broken):

image

Fixed:

image

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
You can’t perform that action at this time.