Обход ловушки предварительного приема, если ветвь уже существует (нажата) - PullRequest
0 голосов
/ 23 апреля 2020

У меня есть ловушка предварительного получения, чтобы проверить соглашение об именах для запуска Git проекта:

valid_branch_regex="^(master|release-[0-9]{4}-[0-9]{2}|[A-Z|0-9]{3,6}-[0-9]+-.*)"

while read oldrev newrev refname; do
    echo "$refname : $oldrev ~ $newrev"
    current_branch=$refname
    short_current_branch="$(echo $current_branch | sed 's/refs\/heads\///g')"
done

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract:\
 $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $short_current_branch =~ $valid_branch_regex ]]
then
    echo "$message"
    exit 1
fi

exit 0

Проблема в том, что я хочу обойти ветви, которые были переданы до применения скрипта. Есть идеи улучшить мой текущий лог c?

Спасибо!

1 Ответ

0 голосов
/ 28 апреля 2020

Возможно, это решение вопроса:

valid_branch_regex="^(master|release-[0-9]{4}-[0-9]{2}|[A-Z|0-9]{3,6}-[0-9]+-.*)"

zero_commit="0000000000000000000000000000000000000000"
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: \
$valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
while read oldrev newrev refname; do
    echo "$refname : $oldrev ~ $newrev"
    current_branch=$refname
    short_current_branch="$(echo $current_branch | sed 's/refs\/heads\///g')"
done

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract:\
 $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
    # Check for new branch or tag
    if [ "$oldrev" == "$zero_commit" ]; then
        short_current_branch="$(echo $current_branch | sed 's/refs\/heads\///g')"
    else
        echo "This is an existing branch, wont check the naming convention. \
Please be aware that the branch name should follow this contract: $valid_branch_regex"
        exit 0
    fi

if [[ ! $short_current_branch =~ $valid_branch_regex ]]
then
    echo "$message"
    exit 1
fi

exit 0 
    if [[ ! $short_current_branch =~ $valid_branch_regex ]]
    then
        echo "$message"
        exit 1
    fi

done
exit 0
...