원격 베어 리포지토리에 배치 된 사전 수신 후크로 푸시 충돌을 방지하는 방법은 무엇입니까?

후안

제 베어 레포에 Master와 스페인어로 개발 된 "desarrollo"라는 두 개의 분기가 있습니다. 중앙에 충돌을 일으키지 않도록 사전 수신 후크를 만들고 싶습니다. 이 후크는 중앙 베어에 배치됩니다. 이것이 내가 가진 것입니다.

#!/bin/bash

protected_branch='master'





# check each branch being pushed


while read local_ref local_sha remote_ref remote_sha

do

if git diff "$old_sha" "$new_sha" | grep -qE '^+?(<<<<<|>>>>>)'; then
    echo "Saw a conflict marker in $(basename "$refname")."
    exit 1
fi

remote_branch=$(echo $remote_ref | sed -e 's,.*/\(.*\),\1,')

if [ $protected_branch = $remote_branch ]

then

echo "ABORT PUSH: Not allowed to push directly to $protected_branch."

exit 1 # push will not execute

fi

done

exit 0

첫 번째 부분은 충돌하는 파일의 푸시를 방지하는 것이고 두 번째 부분은 마스터로의 푸시를 방지하는 것입니다. 저는 desarrollo 브랜치에 대한 푸시 만 허용합니다. 두 번째 부분은 완벽하게 작동하지만 첫 번째 부분은 푸시를 방지하지 않지만 마크 업이있는 파일을 업로드하려고 할 때도 오류가 발생하지 않습니다. 충돌하는 파일을 거부 할뿐만 아니라 충돌하는 파일이 하나라도있는 경우 전체 푸시를 거부하고 트랜잭션이 모두 실패하기를 원합니다.

if git diff "$old_sha" "$new_sha" | grep -qE '^+?(<<<<<|>>>>>)'; then
        echo "Saw a conflict marker in $(basename "$refname")."
        exit 1
    fi

다른 소스에서 두 부분을 모두 복사했다고 말해야하므로 변수 이름에 문제가있을 것입니다. 제가 알고 싶은 것은 old_sha이고 new_sha 변수가 후크를 만드는 데 특히 능숙하지 않기 때문에 이것이 실패하는 이유입니다.

편집 : 문자열 비교를 5에서 7 '<<<<<<<'로 변경했으며 이제 완벽하게 작동하며 최종 스크립트는 다음과 같습니다.

#!/bin/bash

protected_branch='master'


# check each branch being pushed


while read old_sha new_sha refname
do

if git diff "$old_sha" "$new_sha" | grep -qE '^+?(<<<<<<<|>>>>>>>)'; then
    echo "Saw a conflict marker in $(basename "$refname")."
    exit 1
fi

remote_branch=$(echo $refname | sed -e 's,.*/\(.*\),\1,')

if [ $protected_branch = $remote_branch ]

then

echo "ABORT PUSH: Not allowed to push directly to $protected_branch."

exit 1 # push will not execute

fi

done

exit 0
흡혈귀

당신의 동안은 잘못된 것 같습니다. git help hooks에 대한 섹션에서 볼 수 있듯이 pre-receive입력은 <old-value> SP <new-value> SP <ref-name> LF라인 당이므로 while아마도 while read old_sha new_sha refname. 그런 다음 원래 충돌 확인이 정확해야하며 $refname대신 사용하도록 분기 보호를 조정하면 $remote_ref모든 것이 작동 할 것입니다.

pre-push입력이 한 <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF줄에 있는 스크립트 에서이 부분을 복사했을 것입니다 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관