mroth / scmpuff

:1234: Numeric file shortcuts for common git commands
https://mroth.github.io/scmpuff/
MIT License
379 stars 21 forks source link

failed to decode in fish shell #78

Open jsravn opened 1 year ago

jsravn commented 1 year ago

Started using scmpuff in fish shell and it keeps failing to decode. Any ideas? Here is an example:

❯ gs
2022/12/03 12:42:03 
Failed to decode git status change code for chunk: [ A day2/day2.pro]
Please file a bug including this error message as well as the output of:

git status --porcelain

You can file the bug at: https://github.com/mroth/scmpuff/issues/

❯ git status --porcelain
 M aoc2022.pro
 A day2/day2.pro
 A day2/in.txt
 A day2/main.cpp

❯ scmpuff version
scmpuff 0.5.0
mroth commented 1 year ago

Interesting. Does this only happen in fish in the same repository?

It looks like for some reason when this goes to process the change codes (https://github.com/mroth/scmpuff/blob/master/commands/status/process.go#L305), it's seeing an invalid code. Normally these change codes are two bytes. It looks like in this case you are simply adding some new files, so we would expect to see [A ] as the change code but instead we are seeing [ A] (quick conclusion from eyeballing it anyhow).

Could you run git status -z -b > output_fish.txt in an affected repository and attach the file? (The output will contain NUL bytes, so a cut and paste into the issue won't work). git status -z -b is the command run under the hood by scmpuff to get the status, which shouldn't be affected by the shell (we try to call the git binary directly), but.... (if you can run it in bash/zsh as well in the same directory and produce the file for comparison, that could help rule out any issues).

jsravn commented 1 year ago

output_fish.txt

❯ gs
2022/12/03 15:51:55 
Failed to decode git status change code for chunk: [ A day3/test.cpp]
Please file a bug including this error message as well as the output of:

git status --porcelain

You can file the bug at: https://github.com/mroth/scmpuff/issues/

❯ hexdump -C output_fish.txt
00000000  23 23 20 6d 61 69 6e 2e  2e 2e 6f 72 69 67 69 6e  |## main...origin|
00000010  2f 6d 61 69 6e 00 20 4d  20 64 61 79 33 2f 64 61  |/main. M day3/da|
00000020  79 33 2e 70 72 6f 00 20  41 20 64 61 79 33 2f 74  |y3.pro. A day3/t|
00000030  65 73 74 2e 63 70 70 00  20 41 20 64 61 79 33 2f  |est.cpp. A day3/|
00000040  74 65 73 74 2e 68 00 3f  3f 20 64 61 79 33 2f 6f  |test.h.???? day3/o|
00000050  75 74 70 75 74 5f 66 69  73 68 2e 74 78 74 00     |utput_fish.txt.|
0000005f
jsravn commented 1 year ago

Hmm same issue in bash, so I guess it's unrelated to the shell like you say.

jsravn commented 1 year ago

Ah, so it's when a file is added with the -N flag in git, aka git add -N test.txt. I never use that flag normally - but apparently QtCreator (which I started playing with recently) adds files with it, which is what was triggering this.

mroth commented 1 year ago

Fascinating! It's not documented as a possible status in the XY table for https://git-scm.com/docs/git-status (see "short format" section), but there are a few other undocumented things there too.

What does a normal git status show in this case? (We can code this case in to scmpuff, but I'm trying to understand what the UI for how that status is displayed to the user normally is).

jsravn commented 1 year ago

When adding a file with -N:

❯ git status
On branch main
Your branch is up to date with 'origin/main'.

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)
    new file:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")
howardburgess commented 1 year ago

Seems related to #53.