如何在pre push hook的上下文中获取被推送到的分支列表?我知道如何获取当前分支,但它可能与被推送到的一个/多个分支不同。我想过解析这个命令,但我担心我可能会忘记一些情况。比如git push,git push origin master都将推送到master等等。
git push
git push origin master
jmo0nnb31#
while read oldrev newrev refname do if [[ "$newrev" != "0000000000000000000000000000000000000000" ]] ; then branch=${refname#refs/heads/} fidone
while read oldrev newrev refname
do
if [[ "$newrev" != "0000000000000000000000000000000000000000" ]] ; then
branch=${refname#refs/heads/}
fi
done
字符串
qybjjes12#
这里有一个可能的循环,尽管我不清楚你想对远程分支或标记名和/或本地引用做什么:
#! /bin/shNULLSHA=0000000000000000000000000000000000000000 # 40 0'ssay() { echo "$@" 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;; esacdone
#! /bin/sh
NULLSHA=0000000000000000000000000000000000000000 # 40 0's
say() {
echo "$@" 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;;
字符串(note:这一点没有得到很好的测试)。
2条答案
按热度按时间jmo0nnb31#
字符串
qybjjes12#
这里有一个可能的循环,尽管我不清楚你想对远程分支或标记名和/或本地引用做什么:
字符串
(note:这一点没有得到很好的测试)。