chshersh / zbg

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

Idea: `zbg undo` #20

Open Drarig29 opened 1 year ago

Drarig29 commented 1 year ago

I think I don't need it anymore, but when anyone starts using git, a thing that we would really want is a Ctrl+Z, haha :grin:

So the idea would be to have a zbg undo command that looks at the current state of git and aborts it when it's supported, or undoes the commit otherwise.

chshersh commented 1 year ago

@Drarig29 Thanks for the idea! This looks interesting, however, I feel conflicted about this.

In my experience, it's a bad practice to hide multiple entirely different behaviors under the same feature. I imagine it would be quite tiresome to make the state guessing logic robust and test it, and currently I don't have the capacity to do this.

I do like the idea of having an undo command but I don't know what would be a good default for this.

Note

zbg already has the unstash command to pop the latest stashed changes and uncommit to undo the latest commit

I can see this command being more useful probably with an extra explicit argument:

I'll keep the issue open to gather feedback.

Drarig29 commented 1 year ago

multiple entirely different behaviors under the same feature

But I think that's exactly what Ctrl+Z does, and we are used to it in GUIs. Depending on what you just did, in a GUI a Ctrl+Z could move a file back where it was, undelete a file, remove a a stroke in a drawing...

I imagine it would be quite tiresome to make the state guessing logic robust

Actually, it might be a lot easier than what you think. Git creates well-known files in the .git folder to keep track of its state (see this SO answer).

So I don't think there would be any "guessing" involved. Just a list of files to look at.

This feature should have a precise description of the, saying something like "this command aborts the current state if abort-able, or undoes the commit otherwise". And we would really stick to only that. Nothing more complex. Basically, the logic should be explainable in one sentence.

Other thoughts:

Since you already have unstash and uncommit though, maybe the fall back should be to do nothing, with a message saying "Nothing to undo".

Maybe the command should have a confirmation? This way, the user can ensure what's going to happen is what's intended. For example, "Merge in progress... Do you really want to abort the merge? y/[n]"

I can see this command being more useful probably with an extra explicit argument

As soon as I see the 2 words "undo merge" together in the same command, I feel like "undo" becomes not the right verb. One could think it means we are going to undo the merge commit for example.

To me, if we use "undo" it should be a ctrl+z, and have no extra arguments.

and currently I don't have the capacity to do this.

I would be willing to do a PR if we reach an agreement 😄