seachicken / gh-poi

✨ Safely clean up your local branches
https://dev.to/seachicken/safely-clean-up-your-local-branches-9i3
MIT License
642 stars 17 forks source link

remotes regex doesn't match github URLs without username #107

Closed beahues closed 1 year ago

beahues commented 1 year ago

Describe the bug

When running against local SSH repos the regex at https://github.com/seachicken/gh-poi/blob/fdbd0f3241134c6def1a4706f438533211f6c48d/cmd/root.go#L153 doesn't match my remotes that do not start with git@:

 ~/repos/repo > git remote set-url origin github.com:mycompany/repo
 ~/repos/repo > gh poi --debug
2023/06/28 10:47:54 [46.767667ms] run git [remote -v] -> "origin\tgithub.com:mycompany/repo (fetch)\norigin\tgithub.com:mycompany/repo (push)\n"
not found

 ~/repos/repo > git remote set-url origin github.com:mycompany/repo.git
 ~/repos/repo > gh poi --debug
2023/06/28 10:47:59 [54.521291ms] run git [remote -v] -> "origin\tgithub.com:mycompany/repo.git (fetch)\norigin\tgithub.com:mycompany/repo.git (push)\n"
not found

 ~/repos/repo > git remote set-url origin git@github.com:mycompany/repo
 ~/repos/repo > gh poi --debug
2023/06/28 10:48:05 [57.775833ms] run git [remote -v] -> "origin\tgit@github.com:mycompany/repo (fetch)\norigin\tgit@github.com:mycompany/repo (push)\n"
2023/06/28 10:48:05 [18.830916ms] run ssh [-T -G github.com] -> *****

Testing that with the golang regex at https://regex101.com/r/6FqUBq/1 confirms this.

(I realise this is a simple fix my end, set the remote with the git@ in it)

Changing the regex to

^(.+?)\s+(?:\w+@|//)?([a-zA-Z][a-zA-Z0-9-]+\.[a-zA-Z][a-zA-Z0-9-]+?)(?::|/)(.+?/.+?)(?:\.git|)\s+.+$

appears to work for me, and passes tests, but it feels a very much "works for me" fix.

I can happily make https://github.com/beahues/gh-poi/commit/c27e54839b752fc75e730d77375a4bc29d51cd32 in to a PR though?

Your Environment

> git --version
git version 2.41.0
seachicken commented 1 year ago

Thanks for reporting! We need to modify it so that it works even if the username is missing.

Your regex doesn't support https. (e.g. origin https://github.com/mycompany/repo (fetch)) https://regex101.com/r/JwGy8O/1

Feel free to open a PR 🙂

beahues commented 1 year ago

Made #108 which passes tests at the very least 😸

seachicken commented 1 year ago

I just released v0.9.4! Please run gh ext upgrade poi.