我正在寻找别名实际的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