linux - Unable to get right git branch name in bash -
i'm working on post-receive of git server automatically uploads latest version of website in folder named after branch commit in, somehow doing code doesn't work intended.
somehow value branch gets values of branches instead of branch i'm trying get. hash right hash code. have tested outside of program, branch when type right hash. did use wrong syntax in program?
#!/bin/sh hash=$(git log -n 1 --pretty=format:"%h") branch=$(git branch --contains $(git log -n 1 --pretty=format:"%h")) if [ branch ] git_work_tree="/data/site/'$branch'" echo "/data/site/'$branch'" git checkout -f $branch fi
alright, got work wanted! after hearing post-receive got refname stdin, found out had trim down refname branch name , came bit of code. guys. :)
#!/bin/sh while read oldrev newrev refname branch=${refname##*/} if [ branch ] path="/data/site/$branch" mkdir $path unset git_index_file export git_work_tree=$path git checkout -f $refname echo "successfully pushed $path" fi done
Comments
Post a Comment