0
我怎樣才能像已經被推到在預推掛鉤的背景下,新的分支?我知道如何獲得當前分支,但它可能與推送到的一個/多個分支不同。混帳prepush掛鉤:獲取分支推到
我以爲解析命令,但我擔心我可能會忘記某些情況下。像git push
,git push origin master
都將推動掌握等
我怎樣才能像已經被推到在預推掛鉤的背景下,新的分支?我知道如何獲得當前分支,但它可能與推送到的一個/多個分支不同。混帳prepush掛鉤:獲取分支推到
我以爲解析命令,但我擔心我可能會忘記某些情況下。像git push
,git push origin master
都將推動掌握等
while read oldrev newrev refname
do
if [[ "$newrev" != "0000000000000000000000000000000000000000" ]] ; then
branch=${refname#refs/heads/}
fi
done
這裏有一個可能的循環,但要與遠程分支或標記名稱做什麼目前尚不清楚對我來說,和/或本地REF:
#! /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
(注:這是不是很好的測試)。
接近,但並不完全正確:看到git的鉤子文件的預推鉤部分的'裁判/頭/主裁判67890 /頭/國外12345'例如:https://www.kernel.org/酒吧/軟件/ SCM /混帳/文檔/ githooks.html – torek
看起來像'$(回聲$ {refname#裁判/頭/} | awk的 '{$打印1;}')''會使其工作 – Guig
@Guig:簡單:'while read ref localhash foreignref foreignhash; do ...'但是你也應該檢查'refname'(我將重命名爲'localref')實際上也是以'refs/heads /'開始的,否則推動標籤'v1.2'將嘗試去做*分支*'v1.2',可能不存在。 – torek