mhutchie / vscode-git-graph

View a Git Graph of your repository in Visual Studio Code, and easily perform Git actions from the graph.
https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph
Other
1.9k stars 244 forks source link

Support for Git File Type Changes (e.g. symbolic links <-> files) #522

Open marco-m-pix4d opened 3 years ago

marco-m-pix4d commented 3 years ago

Describe the Bug

Git allows to track symlinks. If a file was originally added to a git repo as a symlink, and subsequently is replaced with a normal file (so the name stays the same), it will be reported as typechange:

$ git status
...
    typechange: foo

This extension:

Steps to Reproduce

$ git init
$ touch foo
$ ln -s foo bar
$ ls -l
lrwxrwxrwx bar -> foo
-rw-r--r-- foo
$ git add bar foo
$ git commit -m 1
[master (root-commit) 1b5fc81209] 1
 2 files changed, 1 insertion(+)
 create mode 120000 bar
 create mode 100644 foo
$ code --add .
$ rm bar
$ touch bar
$ git status
On branch master
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)
        typechange: bar

no changes added to commit (use "git add" and/or "git commit -a")

The extension shows:

graph

NOTE: The reproduction steps above use an empty file for simplicity, but the bug is present also if the file is not empty.

Expected Behaviour

The panel to the right of "Displaying all uncommitted changes." should show file bar.

Environment

Additional Context (optional)

Note that I am using Git Graph with the Remote SSH extension.

Additional notes

Once more, thanks for Git Graph!

mhutchie commented 3 years ago

Hi @marco-m-pix4d,

The extension currently runs git status --untracked-files=all --porcelain to determine the number of uncommitted changes (1 in your example). However when retrieving the files to display in the Commit Details View, the commands git diff --name-status --find-renames --diff-filter=AMDR HEAD and git diff --numstat --find-renames --diff-filter=AMDR -z HEAD are used. As expected by the currently used value of the --diff-filter argument, only additions, modifications, deletions and renames are returned - not type changes "T".

Visual Studio Code's in-built Git Extension doesn't support type changes - it also only supports additions, modifications, deletions and renames. image

Currently type changes are not supported in the extension as: they are such a rare edge case, are complicated to implement well (given the lack of available information from Git), and to be consistent with Visual Studio Code's implementation.

However, the example you've provided highlights that the current behaviour in the extension is inconsistent, as type changes are counted for "Uncommitted Changes (1)", but not shown in the Commit Details View. I'll change this to an improvement request to add support for type changes throughout the entire extension.

marco-m-pix4d commented 3 years ago

Hello @mhutchie, thanks for the quick and detailed explanation.

I now understand that, since vscode itself (via the built-in extension) doesn't support git type changes, it can be complicated / unclear if justified to implement support for this in Git Graph.

If I could choose, I would prefer for this extension to stay lean and quick (in general, not only for this particular feature), so for sure I will leave up to you to decide if and how to prioritize this feature.

Thanks!

sanmai-NL commented 11 months ago

I disagree that symlinks are so rare though. We use them all the time to refer to boilerplate files inside submodules.