Skip to content

Commit 5ffb9e7

Browse files
committed
Validate that the branch name sha is present as a commit hash
1 parent b42b8a9 commit 5ffb9e7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cherry_picker/cherry_picker/cherry_picker.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,16 @@ def get_base_branch(cherry_pick_branch):
421421

422422
if prefix != 'backport':
423423
raise ValueError('branch name is not prefixed with "backport-". Is this a cherry_picker branch?')
424+
424425
if not re.match('[0-9a-f]{7,40}', sha):
425-
raise ValueError('branch name has an invalid sha')
426+
raise ValueError(f'branch name has an invalid sha: {sha}')
427+
428+
cmd = ['git', 'log', '-r', sha]
429+
try:
430+
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
431+
except subprocess.SubprocessError:
432+
raise ValueError(f'The sha listed in the branch name, {sha}, is not present in the repository')
433+
426434
# Subject the parsed base_branch to the same tests as when we generated it
427435
# This throws a ValueError if the base_branch doesn't need our requirements
428436
version_from_branch(base_branch)

0 commit comments

Comments
 (0)
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