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

时间:2011-06-01 12:45:23

标签: git github

由于github没有执行(jekyll的safe选项)插件,我正在尝试开发一种小而干净的方法将已编译的文件部署到分支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

和文件.nojekyll(我正在使用here中的子树命令)

然而,这不起作用。它会生成包含所有代码的site分支,但是当我合并到master时,它只是说:

  

已经是最新的。

如何解决这个问题?

我想要完成的是覆盖master中的任何现有文件但不删除分支site中不存在的文件(如前面提到的Makefile和{{1保留在那里非常重要。)

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

1 个答案:

答案 0 :(得分: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

玩得开心o /


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

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