Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add more safeguards to git clear #1167

Open
Welding-Torch opened this issue Sep 28, 2024 · 4 comments
Open

Please add more safeguards to git clear #1167

Welding-Torch opened this issue Sep 28, 2024 · 4 comments

Comments

@Welding-Torch
Copy link

Hi,

This issue is in regards to the git clear command.

I was showing git extras to some people today using the git repl. I typed clear to clear the text in the repl. It asked me if I was Sure. I thought it was asking me if I was sure that I wanted to clear my screen. I didn't think for more than a few seconds about it and I typed "y" for yes. It didn't clear my screen. What it actually did was hard delete 4 files worth of code that existed only in that directory with no other copies.

I do realise that this is my mistake and that I was in a rush, so I didn't pay enough attention.

However, I still want to urge @tj and team to add some more loud safeguards to git clear so that users understand that the action they are about to take is absolutely irreversible and will delete un-tracked code. I would suggest doing this by:

  1. Printing the line Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: in CAPITAL and red color letters.
  2. Asking the user a second time just to make sure. And printing the list of files that are about to be affected by this command.

Thank you. I sincerely hope you act on this.

@hyperupcall
Copy link
Collaborator

hyperupcall commented Sep 29, 2024

Hello! Thanks for the report; I've made a PR that writes part of the warning in uppercase characters. I haven't implemented the red colors part and printing the list of files since that is slightly less straightfoward. (printing red colors should only be done conditionally (only if stdin is a tty), and that requires some common logic, which this repository isn't quite set up for). In the future, hopefully more can be done

@vanpipy
Copy link
Collaborator

vanpipy commented Sep 29, 2024

There is a git-clear-soft and i think to do the more safeguards in it will be better. But I dont think to make more safeguards is a good way cause to use git reset --hard is the way user must know what happened when invoking it.

@Welding-Torch
Copy link
Author

@hyperupcall Hi, thank you so much for responding to this issue and making a PR quickly. This PR is good, capital letters are a good start.

I haven't implemented the red colors part and printing the list of files since that is slightly less straightfoward.

I understand, you've tackled a part of the problem quickly. I'm hoping that the next PR will have asking the user to confirm (y/N) a second time, because that would also be quick and easy to implement.

The red colored text should first check if the terminal supports colored text and only then print it. And as for listing the files, git clear already prints the list of files after the command has been executed. So the logic needs to just be tweaked slightly to print the list of files affected before the command is finished, as seen in this image
image

Hope this helps 👍

@Welding-Torch
Copy link
Author

This might help as a reference for adding red colored text in the terminal: https://jvns.ca/blog/2024/10/01/terminal-colours/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants