NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
3.71k stars 221 forks source link

NeogitStatus sometimes messes up filename, cant toggle file open #1256

Open mangelozzi opened 3 months ago

mangelozzi commented 3 months ago

Description

In the Neogit status it shows files name like:

Modified       s -> Gateway/Gateway.NextClient/src/app/app-route-strategy.t

Instead of (this is from the CLI):

modified:   Gateway.NextClient/src/app/app-route-strategy.ts

Because it has the wrong filenames, it can't toggle it open

Neovim version

NVIM v0.10.0-dev-1224+gdfa8b582a Build type: RelWithDebInfo LuaJIT 2.1.1695653777 Run "nvim -V1 -v" for more info

Operating system and version

Ubuntu 22.04

Steps to reproduce

Not sure, I tried to create blank report, with the same dir structure, relative to the current PWD, but it did not do it then. I think the file has to be modified and renamed.

Expected behavior

The correct file name to show, if I exit neovim, and perform a git status at the command line:

$ gs
On branch feature/prod-det8
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    Gateway.NextClient/src/app/shopping/shopping.route-strategy.ts -> Gateway.NextClient/src/app/app-route-strategy.ts
        modified:   Gateway.NextClient/src/app/app.module.ts
        renamed:    Gateway.NextClient/src/shared/utils/reuse-route.ts -> Gateway.NextClient/src/shared/utils/route-snapshot-tools.ts

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)
        modified:   Gateway.NextClient/src/app/app-route-strategy.ts
        modified:   Gateway.NextClient/src/app/shopping/items/components/product-page/product-page.component.ts
        modified:   Gateway.NextClient/src/modules/cart-preview/cart-preview.component.html
        modified:   Gateway.NextClient/src/modules/cart-preview/cart-preview.component.ts
        modified:   Gateway.NextClient/src/modules/cart-preview/shared.cart-preview.module.ts
        modified:   Gateway.NextClient/src/modules/filtering/inventory-filters/inventory-filters.component.ts
        modified:   Gateway.NextClient/src/styles.scss

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        Gateway.NextClient/extra-webpack.config.js
        Gateway.NextClient/scripts/
        Gateway.NextClient/src/app/landing-page/components/lp-layout/spike.md
        Gateway.NextClient/src/config/gitcommit.ts
        Gateway.NextClient/src/config/version.ts
        Gateway.NextClient/src/modules/ngx-editor-wrapper/ngx-editor-img-upld-tool/

Actual behavior

This is what Neogit shows:

Hint: [<tab>] toggle diff | [s] stage | [u] unstage | [x] discard | [<unmapped>] commit | [?] help

Head:     0abb70ea4 feature/prod-det8 adding route strategies
Tag:      vNext (1352)

Untracked files (6)
Unstaged changes (7)
Modified       s -> Gateway/Gateway.NextClient/src/app/app-route-strategy.t
Modified       Gateway/Gateway.NextClient/src/app/shopping/items/components/product-page/product-page.component.ts
Modified       Gateway/Gateway.NextClient/src/modules/cart-preview/cart-preview.component.html
Modified       Gateway/Gateway.NextClient/src/modules/cart-preview/cart-preview.component.ts
Modified       Gateway/Gateway.NextClient/src/modules/cart-preview/shared.cart-preview.module.ts
Modified       Gateway/Gateway.NextClient/src/modules/filtering/inventory-filters/inventory-filters.component.ts
Modified       Gateway/Gateway.NextClient/src/styles.scss

Staged changes (3)
Renamed        s -> Gateway/Gateway.NextClient/src/app/app-route-strategy.t
Modified       Gateway/Gateway.NextClient/src/app/app.module.ts
Renamed        Gateway/Gateway.NextClient/src/shared/utils/reuse-route.ts -> Gateway/Gateway.NextClient/src/shared/utils/route-snapshot-tools.ts

Stashes (10)
Recent commits (10)

s -> Gateway/Gateway.NextClient/src/app/app-route-strategy.t should be Gateway/Gateway.NextClient/src/app/app-route-strategy.ts (Note the ending s)

Because it has the wrong filenames, it can't toggle it open

Minimal config

Maybe we can brain storm ideas of how to make it reproducible, sorry!
CKolkey commented 3 months ago

Since you're on 0.10, can you try the nightly branch to see if the issue still occurs? :)

And when you have a chance, can you capture the output of git status -z --porcelain=2 -b?

If you feel up to it, and want to do some debugging, this is the bit that's parsing the status output: https://github.com/NeogitOrg/neogit/blob/fd63c19287cb275ea38d2c85f41ce712a816c160/lua/neogit/lib/git/status.lua#L56-L68

mangelozzi commented 3 months ago

Okay cool will do, unfortunately the repo has moved on from there, but when it next happens will try this, thanks!

mangelozzi commented 3 months ago

The good news is that it happened again, I tried nightly: Add back statuscolumn for some buffers

E5108: Error executing lua: ...k/packer/start/neogit/lua/neogit/buffers/status/init.lua:844: table index is nil
stack traceback:
        ...k/packer/start/neogit/lua/neogit/buffers/status/init.lua:844: in function 'open'
        .../share/nvim/site/pack/packer/start/neogit/lua/neogit.lua:115: in function 'open_status_buffer'
        .../share/nvim/site/pack/packer/start/neogit/lua/neogit.lua:187: in function 'open'
        /home/michael/.config/nvim/after/plugin/neogit.lua:142: in function </home/michael/.config/nvim/after/plugin/neogit.lua:142>

So I tried about 8 commit up to 2 weeks ago (Clean up docs) and still get the same error every time.

I think to replicate the issue:

  1. Rename a file that is under version control
  2. Stage the rename
  3. Make a change to the renamed file
  4. Try stage the update.
cjgibbons commented 2 months ago

I traced this back to an overly aggressive regex which caused the original filename to NOT be included in the string returned for matching against renamed files in lib/git/status.lua. I've added the fix in PR #1281.

Note: This PR was against stable since the problem was easily reproducible there.