chshersh / zbg

✨ Zero Bullshit Git
Mozilla Public License 2.0
187 stars 11 forks source link

Colour staged files in 'zbg status' #16

Closed chshersh closed 11 months ago

chshersh commented 1 year ago

Currently, zbg doesn't highlight already staged files in any way like git status does. I think it would be a good idea.

Maybe highlight file names as bold green if the file was staged?

git

image

zbg

image

LeedsJohn commented 11 months ago

Hi, I am interested in working on this issue. I am slightly confused about the behavior of the command used in get_file_statuses - it calls git diff --name-status {commit}, but when I call that command manually with two modified files (and one staged), it lists both files as modified. My impression was that if a file is staged, it should be listed as added. (edit: I've realized that a lot of my confusion comes from Git terminology - if a file is "Added," it means it was just created but git add stages a file as opposed to "adding" it)

This feature is also slightly complicated by the current implementation of the Git.status function. The status function currently stages all deleted and untracked files, calls show_pretty_diff, and then unstages those files. So, if we create a function to get the staged files in show_pretty_diff, it will incorrectly label deleted and untracked files as staged.

One solution that I have considered is creating a list of staged files before staging deleted and untracked files. This can then be passed to show_pretty_diff, and then the "real" staged files can be labeled as "Added." What do you think about this idea?

One edge case that should be considered is how to color a file (say, foo.txt) that has been modified, added, and then modified again. If you do this and call git status, it will list foo.txt under the staged files and the modified files. Perhaps zbg status could color that file yellow.

I suspect that these issues could be solved more elegantly by changing get_file_statuses to call git status --porcelain instead of git diff.

Let me know if you have any thoughts - thanks!

Edit: After realizing that the patch_type contains no information about whether a file has been staged or not, I am more confident that we will need to pass a list of "real" staged files to print_file_statuses.

chshersh commented 11 months ago

I don't have goals to replace git with zbg. So if zbg loses some non-critical information, I'm fine with that. I don't really want to complicate the project to support some rare and weird corner cases.

Besides, in my personal workflows, I usually commit everything I touch 😅

I like the idea of getting staged files before the main status pretty-printing work 👍🏻