我正在尋找別名實際的git push
命令在Git中運行的東西像單元測試之前提交到GitHub。Alias Git推送命令與自定義腳本
這是我config
文件中.git/
[alias]
push = !echo "custom push"
kk = !echo "hi" # => this works...
它似乎忽視了推動。這可能嗎?如果這是不可能的,有沒有其他的選擇?
我正在尋找別名實際的git push
命令在Git中運行的東西像單元測試之前提交到GitHub。Alias Git推送命令與自定義腳本
這是我config
文件中.git/
[alias]
push = !echo "custom push"
kk = !echo "hi" # => this works...
它似乎忽視了推動。這可能嗎?如果這是不可能的,有沒有其他的選擇?
而不是創建一個別名,我會使用git的預先提交鉤子。
你不能別名推由於與推出指令衝突,但你可以嘗試使用「推前」掛鉤,請參閱以下patch瞭解更多詳情。
另一種方法是在GitHub上使用post-receive掛鉤,您將其配置爲對您的集成服務器執行POST操作,該服務器將運行單元測試等,並批准或拒絕更改。然而,取決於你的設置,這可能不實際。
嗯..這真的很難遵循 - 這是修補實際的git庫嗎?我認爲這有點矯枉過正.. – Matt 2012-04-19 23:42:33
是的,這不是非常簡單。也許創建一個'xpush'別名是一個更好的選擇。 – BluesRockAddict 2012-04-19 23:48:42
我已經寫了這個來打擊git push
打印出我想運行但不運行它的厭惡!是的,它有理由(你不應該把每一塊垃圾推到遠程),但我的遙控器是我的GitHub叉,我可以忍受任何垃圾推到那裏。
這是基於Eugene Kay's .bashrc
(我保留cd
從那裏,但刪除了which git
部分,這對我不起作用)。添加到.bashrc
或.zshrc
品嚐:
function git() {
# Path to the `git` binary
GIT="/usr/bin/git"
# Sanity check
if [ ! -f ${GIT} ]
then
echo "Error: git binary not found" >&2
return 255
fi
# Command to be executed
command=$1
# Remove command from [email protected] array
shift 1
# Check command against list of supported commands
case $command in
"cd")
cd $(git rev-parse --show-toplevel)/${1}
;;
"push")
if [ -z "$1" ]
then
$GIT push || $GIT push -u origin $($GIT rev-parse --abbrev-ref @)
else
$GIT ${command} "[email protected]"
fi
;;
*)
# Execute the git binary
$GIT ${command} "[email protected]"
;;
esac
# Return something
return $?
}
感謝您的迴應。我寧願在提交時儘可能減少開銷。每次運行單元測試都很痛苦。這應該只在我推送到外部「生產」分支時運行。此外,Github不提供預先接收的鉤子,因此在另一側打它也不起作用。 – Matt 2012-04-19 23:08:20
您可以使用'-n'或'--no-verify'來跳過任何給定提交的'pre-commit'掛鉤。當然,這也會跳過'commit-msg'鉤子,你可能會也可能不想這樣做,如果你養成了習慣使用'-n'的習慣,你可能會忘記把'-n'在你想要檢查的那個上。 :-)這裏沒有完美的解決方案。你只需要選擇你可以忍受的缺點。 – torek 2012-04-20 05:35:50