-
-
Save codingfox-rus/9089528730ab8502728ec87e0facf0d5 to your computer and use it in GitHub Desktop.
pre-push hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import subprocess | |
import re | |
task_pattern = 'DDD\-\d+' | |
# Получаем в выводе только текущую ветку | |
current_branch = subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).decode().strip() | |
curr_branch_parts = current_branch.split('/') | |
curr_branch_key = None | |
for part in curr_branch_parts: | |
if re.match(task_pattern, part): | |
curr_branch_key = part | |
break | |
rem_branches_dict = {} | |
rem_branches = subprocess.check_output(['git', 'branch', '-r']).decode().split('\n') | |
for branch in rem_branches: | |
branch = branch.strip() | |
branch_parts = branch.split('/') | |
for part in branch_parts: | |
if re.match(task_pattern, part): | |
rem_branches_dict[part] = branch[7:] | |
wrong_condition = curr_branch_key in rem_branches_dict and current_branch != rem_branches_dict[curr_branch_key] | |
if wrong_condition: | |
print('Есть удаленная ветка с тем же номером задачи') | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment