带有本地插件的github页面的干净系统

Fla*_*ius 3 git github

由于github不执行(safejekyll 的选项)插件,我正在尝试开发一种小而干净的方式将已编译的文件部署到分支master.

通常的来源是在分支中boilerplate,从那里我运行jekyll并生成代码,一切正常.

在主分支中,我只有以下内容 Makefile

default:
    git checkout boilerplate
    git subtree split -P _site -b site
    git checkout master
    git merge -X theirs site
    git branch -D site
Run Code Online (Sandbox Code Playgroud)

和文件.nojekyll(我在这里使用子树命令)

但这不起作用.它生成site包含所有代码的分支,但是当我合并时master,它所说的全部是:

已经是最新的.

如何解决这个问题?

我想做到的是要覆盖所有现有文件master但不能删除不分支存在的文件site(如前面提到的Makefile.nojekyll,这是重要的是要保持有).

注意:我想从头开始,以便保持对部署过程的控制.我不想1.引入新的依赖项2.使用其他工具.

c00*_*ter 15

正如我在IRC上所说的,我会使用git hook(git help hooks)

this快速破解了脚本.把它放在下面$GIT_DIR/.git/hooks/.

我测试它作为提交后的提交钩子$_origbranch并检查另一个分支($_destbranch)上的结果.

应该做你想做的事.工作得很好,所以我希望它适合你或将其引导到一个正确的方向.

#!/usr/bin/env bash

# executables prefix
_prefix="/usr/bin"
# git executable
_git="$_prefix/git"

# site generation executable
_generate="$_prefix/jekyll"
# options for the generator
_opts=(--no-safe --no-server --no-auto --kramdown)

# branch from which to generate site
_origbranch="master"
# branch holding the generated site
_destbranch="gh-pages"

# directory holding the generated site -- should be outside this repo
_site="$("$_prefix/mktemp" -d /tmp/_site.XXXXXXXXX)"
# the current branch
_currbranch="$(/bin/grep "^*" < <("$_git" branch) | /bin/cut -d' ' -f2)"

if [[ $_currbranch == $_origbranch ]]; then # we should generate the site
    # go to root dir of the repo
    cd "$("$_git" rev-parse --show-toplevel)"
    # generate the site
    "$_generate" ${_opts[@]} . "$_site"
    # switch to branch the site will be stored
    "$_git" checkout "$_destbranch"
    # overwrite existing files
    builtin shopt -s dotglob
    /bin/cp -rf "$_site"/* .
    builtin shopt -u dotglob
    # add any new files
    "$_git" add .
    # commit all changes with a default message
    "$_git" commit -a -m "updated site @ $(date +"%F %T")"
    # cleanup
    /bin/rm -rfv "$_site"
    # return
    "$_git" checkout "$_origbranch"
fi
Run Code Online (Sandbox Code Playgroud)

玩得开心o /


只是更新说这适用于bash和Linux.它也可以用POSIX sh编写.另外,我认为mktemp只是GNU-coreutils,因此其他系统可能需要替换它.

注意:这仅在您指定的分支中提交时运行$_origbranch.你可以改变这一点.我相信这对任何人来说都很简单.