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

Fix detection of upstream version branches with continue #265

Merged

Conversation

abadger
Copy link
Contributor

@abadger abadger commented Jun 16, 2018

cherry_picker has recently grown support for prefixed version branches
(like stable-2.6). The --continue support had a bug with those branches
where it wouldn't account for the fact that those branches could have
extra dashes in them and thus mixing branch name with sha.

This commit should fix those situations.

cherry_picker has recently grown support for prefixed version branches
(like stable-2.6).  The --continue support had a bug with those branches
where it wouldn't account for the fact that those branches could have
extra dashes in them and thus mixing branch name with sha.

This commit should fix those situations.
@webknjaz
Copy link
Contributor

@abadger You need to take into account case when a user might run --continue from a different branch:

=================================== FAILURES ===================================
______________________ test_get_base_branch_without_dash _______________________
    def test_get_base_branch_without_dash():
        cherry_pick_branch ='master'
>       result = get_base_branch(cherry_pick_branch)
cherry_picker/test.py:43: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cherry_pick_branch = 'master'
    def get_base_branch(cherry_pick_branch):
        """
        return '2.7' from 'backport-sha-2.7'
        """
>       prefix, sha, base_branch = cherry_pick_branch.split('-', 2)
E       ValueError: not enough values to unpack (expected 3, got 1)
cherry_picker/cherry_picker.py:425: ValueError
===================== 1 failed, 27 passed in 0.35 seconds ======================

@abadger
Copy link
Contributor Author

abadger commented Jun 16, 2018

Ah... I thought rpartition traced back in that case too but I see now it always returns a three tuple.

I can replicate the previous behaviour here but I'm not sure... is that actually sensible behaviour? From where it's being called, I think that this would cause other bugs.

@abadger
Copy link
Contributor Author

abadger commented Jun 16, 2018

So the two places that get_base_branch is currently called from are:

Thinking about this more, it feels like this function is assuming that it's taking a string of a known format, assigning semantic meaning to pieces of that string based on their position inside of it, and then returning the value that corresponds to one of those meanings. If so, it feels right that the code should raise a ValueError if the string does not conform to the format... Otherwise how would we know what portion of the string was the base branch? Is it all of it? Is it the first piece? The last piece? Or perhaps none of those because we weren't given a string containing the base branch at all?

So I think the test is wrong but perhaps there's some other use case for this code that I am not aware of? @Mariatta ? Input from you?

@abadger
Copy link
Contributor Author

abadger commented Jun 16, 2018

I've pushed a change to the test cases which removes the "no_dash" test and adds one for "dashes in the base branch".

@abadger abadger force-pushed the fix-continue-with-prefixed-version-branches branch from 04e31d5 to f90d993 Compare June 16, 2018 22:32
@webknjaz
Copy link
Contributor

I can replicate the previous behaviour here but I'm not sure... is that actually sensible behaviour? From where it's being called, I think that this would cause other bugs.

Git itself is a very stateful tool, so it's expected that when you rely on it there's some restrictions.

abadger added a commit to abadger/core-workflow that referenced this pull request Jun 16, 2018
When running cherry_picker --continue we count on being able to get
certain information from the branch's name which cherry_picker
constructed earlier.  Verify as best we can that the branch name is one
which cherry_picker could have constructed.

Relies on the changes here: python#265
(which does the work of one of the validations)
@abadger
Copy link
Contributor Author

abadger commented Jun 16, 2018

My question doesn't come from what git does; it comes from what cherry-picker is doing with this branch name. AFAICT, the branch name has to be one that we created (with the three dashes), otherwise the present code will fail. So it seems like the current test that no dashes works is testing something that we'll never want the code itself to do.

@abadger abadger closed this Jun 19, 2018
@abadger abadger reopened this Jun 19, 2018
abadger added a commit to abadger/core-workflow that referenced this pull request Jun 22, 2018
When running cherry_picker --continue we count on being able to get
certain information from the branch's name which cherry_picker
constructed earlier.  Verify as best we can that the branch name is one
which cherry_picker could have constructed.

Relies on the changes here: python#265
(which does the work of one of the validations)
@webknjaz
Copy link
Contributor

webknjaz commented Jul 2, 2018

@Mariatta this PR looks ready :)

@Mariatta
Copy link
Member

Mariatta commented Jul 9, 2018

Sorry for the delay in responding to this! 🙇‍♀️
The original implementation was based on CPython's branch names that doesn't include dashes, so it didn't handle ansible's situation.
Thanks for catching and fixing this!

@Mariatta Mariatta merged commit ff8a587 into python:master Jul 9, 2018
abadger added a commit to abadger/core-workflow that referenced this pull request Jul 9, 2018
When running cherry_picker --continue we count on being able to get
certain information from the branch's name which cherry_picker
constructed earlier.  Verify as best we can that the branch name is one
which cherry_picker could have constructed.

Relies on the changes here: python#265
(which does the work of one of the validations)
@abadger abadger deleted the fix-continue-with-prefixed-version-branches branch July 18, 2018 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants