-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add refname rule checking to branch prefix input dialogue #153
Add refname rule checking to branch prefix input dialogue #153
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Sorry for the late response. One question in the inline comment.
|
||
fn validate_branch_prefix(branch_prefix: &str) -> Result<()> { | ||
// They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock. | ||
if branch_prefix.contains("/.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to check branch_prefix.starts_with(".")
, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I missed the fact that due to the prefix, we get a "/" at the beginning anyway and thus it's not enough to just check for "/.
.
I amended the commit.
b68fde2
to
109560a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thanks for contributing!
Fixes spacedentist#152 This PR addresses the potential invalid refnames resulting from a bad input to the `branchPrefix` question during `spr init`. I debated between two approaches. 1. 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. 2. 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. Reviewers: spacedentist Reviewed By: spacedentist Pull Request: spacedentist#153
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.