2016-09-26 3 views
0

으로 푸시됩니다. 예전 푸시 후크의 컨텍스트에서 푸시되는 브랜치 목록을 얻으려면 어떻게해야합니까? 현재 분기를 얻는 방법을 알고 있지만 하나 또는 여러 분기가 푸시 된 것과 다를 수 있습니다.git prepush hook : 분기가

나는이 명령을 구문 분석 할 생각을 해봤지만 몇 가지 경우를 잊어 버릴지 걱정됩니다. 당신은 원격 지사 또는 태그 이름으로 수행 할 작업을 나에게 분명하지 않다, 및/또는 로컬 심판 있지만 git push처럼 git push origin master은 모두,

답변

1
while read oldrev newrev refname 
do 
    if [[ "$newrev" != "0000000000000000000000000000000000000000" ]] ; then 
      branch=${refname#refs/heads/} 
    fi 
done 
+1

가깝지만 맞지 않습니다. git hooks 문서의 pre-push hook 섹션에있는'refs/heads/master 67890 refs/heads/foreign 12345' 예제를 참조하십시오 : https://www.kernel.org/ pub/software/scm/git/docs/githooks.html – torek

+0

'$ (echo $ {refname # refs/head /} | awk '{print $ 1;}') '''와 같이 보이면 작동하게 될 것입니다. – Guig

+0

@Guig : 더 간단합니다. :'읽는 동안 refname localhash foreignref foreignhash; do'...하지만'refname' (실제로'localref'로 이름을 바꿀 것입니다)이 실제로'refs/heads /'로 시작하는지 확인해야합니다. 그렇지 않으면'v1.2' 태그를 밀면 뭔가를 시도 할 것입니다 * branch *'v1.2'는 아마도 존재하지 않을 것입니다. – torek

0

여기 하나 개의 가능한 루프의 등 마스터 밀어 버린다 :

#! /bin/sh 

NULLSHA=0000000000000000000000000000000000000000 # 40 0's 

say() { 
    echo "[email protected]" 1>&2 
} 

while read localref localhash foreignref foreignhash; do 
    case $foreignref in 
    refs/heads/*) 
     reftype=branch 
     shortref=${foreignref#refs/heads/};; 
    refs/tags/*) 
     reftype=tag 
     shortref=${foreignref#refs/tags/};; 
    *) reftype=unknown-ref-type 
     shortref=$foreignref;; 
    esac 
    say "pushing to $reftype $shortref" 
    case $localhash,$foreignhash in 
    $NULLSHA,*) say "(push with intent to delete)";; 
    *,$NULLSHA) say "(push with intent to create)";; 
    *) say "(push with intent to update from $foreignhash to $localhash)" 
     # for branch updates only, let's see if it's a fast-forward 
     if [ $reftype = branch ]; then 
      if git merge-base --is-ancestor $foreignhash $localhash; then 
       say "(this is a fast-forward)" 
      else 
       say "(this can only work if forced)" 
      fi 
     fi;; 
    esac 
done 

(참고 : 잘 테스트되지 않았습니다).