bash - 预克隆/预初始化 git 挂钩?
问题描述
我试图弄清楚如何最好地编写“预初始化”或“预克隆”钩子。我会为刚刚学习 git 的学生使用它——某种脚本在实际执行启动或克隆 repo 之前一直检查父目录。
我知道 git 中有许多 pre-[action] 挂钩,但在存储库级别,而不是全局级别。有没有办法创建这样的钩子,或者我最好写某种别名?我通读了文档,似乎暗示这种事情是可能的,但没有具体说明如何。
更新:我最终创建了几个别名。他们来了。如果有人对如何使它们变得更好有任何建议,我肯定很感兴趣——bash 脚本不是我的专业领域。
is_git_repo() {
$(git rev-parse --is-inside-work-tree &> /dev/null)
}
is_git_dir() {
$(git rev-parse --is-inside-git-dir 2> /dev/null)
}
check_for_git_repo() {
if is_git_repo || is_git_dir; then
echo "You are currently in a git repository. Please leave this repository and try again."
return 1
fi
}
check_for_git_parent() {
if tree -a -d | grep -q '.git'; then
echo "This directory is not a git repository, but one of its subdirectories is. Please create a new subdirectory and try again."
return 1
fi
}
alias ginit='check_for_git_repo && check_for_git_parent && echo "Creating repository" && git init'
gclone() {
check_for_git_repo && git clone $*
}
解决方案
推荐阅读
- python - 如何从三个 pandas 列中获得第 3 到第 7 最高选择的平均值?
- python - 如何将总天数划分为不同的年份,以免数据集出现偏差?
- javascript - 画布:在循环中绘制图块导致仅绘制单个图块
- arrays - randomSplit期间的scala java.lang.ClassCastException
- r - 如果间隙超过特定时间,则查找持续时间并创建阈值
- c# - 如何使用 foreach 在 Razor 中设置 Viewbag 值?
- java - 依赖注入:应该先做哪个?属性(字段)或依赖项?
- python - Python 类:在将 True 切换为 False 时无法增加自维护以来的行程计数器,也无法在修复后将计数器重置为零
- svelte - 使用 Svelte 没有箭头函数的复选框验证
- c++ - C++ - unordered_map 运算符 [],意外行为