Skip to content

Validate a branch that we parse when running cherry_picker --continue #266

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

Merged
merged 2 commits into from
Jul 13, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Extract the validation of a sha within the repo to a common function
  • Loading branch information
abadger committed Jul 9, 2018
commit 4eba21fa55b5215e5b88906a939a3d56e41a5e2f
41 changes: 29 additions & 12 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def upstream(self):

@property
def sorted_branches(self):
"""Return the branches to cherry-pick to, sorted by version"""
"""Return the branches to cherry-pick to, sorted by version."""
return sorted(
self.branches,
reverse=True,
Expand Down Expand Up @@ -349,12 +349,15 @@ def continue_cherry_pick(self):
click.echo(f"Current branch ({cherry_pick_branch}) is not a backport branch. Will not continue. \U0001F61B")

def check_repo(self):
# CPython repo has a commit with
# SHA=7f777ed95a19224294949e1b4ce56bbffcb1fe9f
cmd = ['git', 'log', '-r', self.config['check_sha']]
"""
Check that the repository is for the project we're configured to operate on.

This function performs the check by making sure that the sha specified in the config
is present in the repository that we're operating on.
"""
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.SubprocessError:
validate_sha(self.config['check_sha'])
except ValueError:
raise InvalidRepoException()


Expand Down Expand Up @@ -416,6 +419,9 @@ def cherry_pick_cli(dry_run, pr_remote, abort, status, push, config_path,
def get_base_branch(cherry_pick_branch):
"""
return '2.7' from 'backport-sha-2.7'

raises ValueError if the specified branch name is not of a form that
cherry_picker would have created
"""
prefix, sha, base_branch = cherry_pick_branch.split('-', 2)

Expand All @@ -425,19 +431,30 @@ def get_base_branch(cherry_pick_branch):
if not re.match('[0-9a-f]{7,40}', sha):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also validate the sha against git (like it's done with a commit in config)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

raise ValueError(f'branch name has an invalid sha: {sha}')

cmd = ['git', 'log', '-r', sha]
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.SubprocessError:
raise ValueError(f'The sha listed in the branch name, {sha}, is not present in the repository')
# Validate that the sha refers to a valid commit within the repo
# Throws a ValueError if the sha is not present in the repo
validate_sha(sha)

# Subject the parsed base_branch to the same tests as when we generated it
# This throws a ValueError if the base_branch doesn't need our requirements
# This throws a ValueError if the base_branch doesn't meet our requirements
version_from_branch(base_branch)

return base_branch


def validate_sha(sha):
"""
Validate that a hexdigest sha is a valid commit in the repo

raises ValueError if the sha does not reference a commit within the repo
"""
cmd = ['git', 'log', '-r', sha]
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.SubprocessError:
raise ValueError(f'The sha listed in the branch name, {sha}, is not present in the repository')


def version_from_branch(branch):
"""
return version information from a git branch name
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy