This PR addresses the potential invalid refnames resulting from a bad input to the branchPrefix question during spr init. I debated between two approaches.
We could just construct a refname based off the branch prefix and run a git command to check if it's a valid refname. I thought that was too hacky and I didn't want to deal with spawning an extra command during the setup.
We could just implement the relevant rules directly. Of course if future git versions change those rules, we'll be out of sync with them. I consider that somewhat unlikely though.
In setting up the code for the rules, I opted for a more verbose approach. We could certainly mash together everything into one big regex with lots of branches. Due to all those escaped special chars, the regex is already ugly enough.
One caveat: Because the refname rules disallow multiple consecutive forward slashes /, our branch prefix must not start with even a single /.
Testing
Unit tests make sure the rules are actually implemented. They should be comprehensive, but they are not exhaustive. For example, there isn't a single test for each and every control character. I trust that the is_control method on char works as advertised...
I also manually tested that the dialogue repeats until an acceptable refname is added.
Fixes #152
This PR addresses the potential invalid refnames resulting from a bad input to the
branchPrefix
question duringspr init
. I debated between two approaches.In setting up the code for the rules, I opted for a more verbose approach. We could certainly mash together everything into one big regex with lots of branches. Due to all those escaped special chars, the regex is already ugly enough.
One caveat: Because the refname rules disallow multiple consecutive forward slashes
/
, our branch prefix must not start with even a single/
.Testing
Unit tests make sure the rules are actually implemented. They should be comprehensive, but they are not exhaustive. For example, there isn't a single test for each and every control character. I trust that the
is_control
method onchar
works as advertised...I also manually tested that the dialogue repeats until an acceptable refname is added.