tbroadley / github-spellcheck-cli

Check a GitHub repository for spelling mistakes and automatically create a pull request :pen:
MIT License
135 stars 14 forks source link

Automatically change branch name if it already exists #108

Open DanielVandH opened 1 year ago

DanielVandH commented 1 year ago

I had made a PR to someones repo with this tool, and then had to follow up with another PR to include some other file types. Unfortunately, after going through all the corrections it then told me that the branch already exists:

Are you sure you want to create a pull request with these corrections? y, n, h: y
Creating a new branch "fix-typos"...
Error: Error: Command failed: git --work-tree="C:\Users\User\.github-spellcheck\DanielVandH\Manopt.jl" --git-dir="C:\Users\User\.github-spellcheck\DanielVandH\Manopt.jl\.git" branch fix-typos ba8d5cffafdbd65a5f81b72ab40240bec1624a04
fatal: a branch named 'fix-typos' already exists

Exiting...

so I then had to go and do the entire thing again (and again after I didn't realise I should've deleted the branch in the github-spellcheck repo rather than my fork of Manopt.jl, but that's on me).

Would it be a good idea to make the branch name change by default if fix-typos already exists (or, if not, check for the existence of this branch first before any work is done) and, if it does, use e.g. fix-typos-2? (and if fix-typos-n exists, sue fix-typos-n+1.) I'd make a PR to address this myself but I don't know any JavaScript to read any of the code.

tbroadley commented 1 year ago

Thank you for pointing this out, Daniel! Sorry for the annoyance. I do think it'd be a good idea for the tool to detect if the fix-typos branch already exists on the remote repo and pick a different name in this situation. I can't promise I'll put up a fix for this soon, though, to be honest.

DanielVandH commented 1 year ago

No worries at all. Would you accept a PR giving a warning about this? e.g. I wrote about this tool here for using it for some Julia packages, and I gave this warning:

WARNING: After you use this tool once for a repository, if you try and use it again for the same repository it will error at the end due to this issue, and you will lose all the changes you have made with no way to recover them. To allow yourself to use the tool again for the same repository, you need to go to ~/.github-spellcheck/UserName/ and delete the folder corresponding to the package. For example, after running the examples below, I then manually delete the folder C:\Users\User.github-spellcheck\DanielVandH\NaturalNeighbours.jl. You also want to delete the branch corresponding to the created pull request (as the GitHub pull request will prompt you to do after the pull request has been merged).

Maybe a more concise version of this warning somewhere in this repo could be appropriate.

tbroadley commented 1 year ago

Sure, I would accept such a PR! Thank you for the suggestion.

tbroadley commented 1 year ago

Also, thank you for writing about this tool! That's cool to see.