Not able to detect branch from Git post-receive hook

前端 未结 5 1520
面向向阳花
面向向阳花 2021-01-31 11:37

I\'ve got a post receive hook setup on the remote repo that tries to determine the branch name of the incoming push as follows:

$branch = `git rev-parse --abbrev         


        
5条回答
  •  梦毁少年i
    2021-01-31 12:23

    Magnus' solution didnt work for me, but this did:

    #!/bin/bash
    
    echo "determining branch"
    
    if ! [ -t 0 ]; then
      read -a ref
    fi
    
    IFS='/' read -ra REF <<< "${ref[2]}"
    branch="${REF[2]}"
    
    if [ "master" == "$branch" ]; then
      echo 'master was pushed'
    fi
    
    if [ "staging" == "$branch" ]; then
      echo 'staging was pushed'
    fi
    
    echo "done"
    

提交回复
热议问题