Skip to content

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

Closed

Description

@kav137
  • 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.

Activity

  1. added
    bug
    and removed on Oct 16, 2017
  2. harimambura commented on Nov 8, 2017

    @harimambura

    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

  3. added
    good first issue
    help wanted
    on Nov 23, 2017
  4. amitdey1987 commented on Feb 8, 2018

    @amitdey1987

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

  5. amitdey1987 commented on Feb 9, 2018

    @amitdey1987

    As Artyom Koval (@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.

  6. harimambura commented on Feb 9, 2018

    @harimambura
  7. lorenzo-arena commented on May 17, 2018

    @lorenzo-arena

    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)

  8. userFromHades commented on Sep 18, 2018

    @userFromHades

    1.27.2 it looks like it's still broken.

  9. 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[/+] on Sep 18, 2018
  10. felipecaputo commented on Oct 29, 2018

    @felipecaputo

    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

  11. rysavyjan commented on Apr 24, 2019

    @rysavyjan

    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?

  12. rysavyjan commented on May 16, 2019

    @rysavyjan

    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

    João Moreno (@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.

  13. KUGA2 commented on Jul 30, 2019

    @KUGA2

    Problem is still occurring in 1.36.1.

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

  14. rafaelgomesxyz commented on Sep 29, 2019

    @rafaelgomesxyz

    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.

  15. removed
    good first issue
    help wanted
    on Nov 20, 2019
  16. joaomoreno commented on Nov 20, 2019

    @joaomoreno
    Contributor

    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

  17. added
    verified
    on Dec 5, 2019
  18. locked and limited conversation to collaborators on Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buggitverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions