2012-04-01 10 views
7

Tôi có file org trong một kho lưu trữ và sử dụng github project pages tương lai. Xuất tệp org thành html để sử dụng trong gh-pages như thế này;html xuất khẩu khác nhau chi nhánh

  • chỉnh sửa org tập tin trên master ngành và cam kết
  • xuất khẩu html vào một thư mục tạm thời
  • thay đổi chi nhánh để gh-pages
  • file sao chép từ thư mục tạm thời và cam kết

là có một cách xuất khẩu trực tiếp đến chi nhánh gh-pages mà không export/change branch/copy chu kỳ này?

Trả lời

2

Tôi cố định vấn đề với việc sử dụng các môđun con git. Bây giờ tôi có thể xuất các tập tin org của tôi vào thư mục dưới master. Thư mục này trên thực tế là một mô-đun con của cùng một kho lưu trữ gh-pages chi nhánh. Bạn có thể kiểm tra của tôi org-publish-project-alist trong repositorypage. Bây giờ chu kỳ phát triển của tôi;

  • Chỉnh sửa trong master sau đó html xuất khẩu
  • Add, đẩy trong gh-pages thư mục
  • Add, đẩy trong thư mục master gốc

Thứ nhất tôi đã thêm gh-pages chi nhánh như đã nói ở github sau đó thêm gh-pages chi nhánh như submodule:

[[email protected] org-test](gh-pages)$ git checkout master 
[[email protected] org-test](master)$ git submodule add -b gh-pages [email protected]:selman/org-test.git gh-pages 
[[email protected] org-test](master)$ git commit -m "branch added as submodule" 

xuất khẩu index.org như html để gh-pages thư mục:

[[email protected] org-test](master)$ cd gh-pages/ 
[[email protected] gh-pages](gh-pages)$ git add . 
[[email protected] gh-pages](gh-pages)$ git commit -m "pages updated" 
[[email protected] gh-pages](gh-pages)$ git push 

submodule Thay đổi bổ sung vào master:

[[email protected] gh-pages](gh-pages)$ cd .. 
[[email protected] org-test](master)$ git add . 
[[email protected] org-test](master)$ git commit -m "pages updated" 
[[email protected] org-test](master)$ git push 
2

Thay vì xuất sang thư mục tạm thời, bạn có thể xuất thành bản sao thứ hai của kho lưu trữ (với chi nhánh gh-pages được kiểm tra).

Nếu bạn muốn có một giải pháp tự động hơn nhưng phức tạp, bạn có thể chạy các kịch bản sau đây sau khi xuất khẩu tập tin của bạn:

#!/bin/sh 

usage() { 
    cat <<EOF 
Usage: $0 [options] [--] <path_to_exported_html_files> 

Arguments: 

    -h, --help 
    Display this usage message and exit. 

    -b <branch>, --branch=<branch>, --branch <branch> 
    Commit the files to the given branch. If the branch doesn't 
    exist, a new root (parentless) commit is created. 
    Defaults to: ${DEFAULT_BRANCH} 

    -- 
    Treat the remaining arguments as path names. Useful if the path 
    name might begin with '-'. 

    <path_to_exported_html_files> 
    Directory containing the html files exported by org-mode. If the 
    path begins with '-', it will be treated as an option unless it 
    comes after the '--' option. 
EOF 
} 

DEFAULT_BRANCH=gh-pages 

# handy logging and error handling functions 
log() { printf '%s\n' "$*"; } 
warn() { log "WARNING: $*" >&2; } 
error() { log "ERROR: $*" >&2; } 
fatal() { error "$*"; exit 1; } 
try() { "[email protected]" || fatal "'[email protected]' failed"; } 
usage_fatal() { error "$*"; usage >&2; exit 1; } 

# parse options 
BRANCH=${DEFAULT_BRANCH} 
while [ "$#" -gt 0 ]; do 
    arg=$1 
    # the quotes around the equals signs in the case patterns below 
    # are to work around a bug in emacs' syntax parsing 
    case $1 in 
     -h|--help) usage; exit 0;; 
     -b|--branch) shift; BRANCH=$1;; 
     --branch'='*) BRANCH=${1#--branch=};; 
     --) shift; break;; 
     -*) usage_fatal "unknown option: '$1'";; 
     *) break;; # reached the path 
    esac 
    shift || usage_fatal "option '${arg}' requires a value" 
done 
[ "$#" -gt 0 ] || usage_fatal "must specify a directory" 
dir=$1; shift 
dir=$(cd "${dir}" && pwd -P) \ 
    || fatal "unable to convert ${dir} to an absolute path" 
[ "$#" -eq 0 ] || usage_fatal "unknown option: $1" 
[ -d "${dir}" ] || usage_fatal "${dir} is not a directory" 

# sanity check: make sure ${BRANCH} isn't currently checked out 
# (otherwise 'git status' will show modified files when this script is 
# done) 
CURRENT_BRANCH=$(try git symbolic-ref HEAD) || exit 1 
case ${CURRENT_BRANCH} in 
    refs/heads/"${BRANCH}") fatal "${BRANCH} must not be checked out";; 
esac 

# set up git 
GIT_DIR=$(git rev-parse --git-dir) \ 
    || fatal "unable to locate .git directory" 
GIT_DIR=$(cd "${GIT_DIR}" && pwd -P) \ 
    || fatal "unable to convert git directory to an absolute path" 
GIT_INDEX_FILE=$(mktemp -u) \ 
    || fatal "unable to generate a temporary file name" 
export GIT_DIR 
export GIT_INDEX_FILE 
export GIT_WORK_TREE="${dir}" 

# stage the files 
try cd "${dir}" 
try git add -Af . 

# commit the files 
PARENT=$(git rev-parse --verify -q refs/heads/"${BRANCH}") \ 
    || warn "creating a new branch named ${BRANCH}" 
TREE=$(try git write-tree) || exit 1 
COMMIT_MESSAGE="Import files from ${dir}" 
COMMIT=$(
    printf '%s\n' "${COMMIT_MESSAGE}" | 
    try git commit-tree "${TREE}" ${PARENT:+-p "${PARENT}"} 
) || exit 1 

# update the branch to point to the result 
try git update-ref refs/heads/"${BRANCH}" -m "commit: ${COMMIT_MESSAGE}" \ 
    "${COMMIT}" 

# clean up 
try rm -f "${GIT_INDEX_FILE}" 

log "committed ${COMMIT} to ${BRANCH}" 
+0

cảm ơn, nó là nhiều tự động so với cách của tôi, nhưng vẫn nhìn xấu xí để có hai bản sao của một kho lưu trữ. –

+0

@SelmanUlug: Tôi đã cập nhật câu trả lời để cung cấp một tập lệnh có thể tự động chuyển các tệp html đã xuất sang chi nhánh 'gh-pages' của bạn mà không cần phải sao chép thứ hai. –

+0

cảm ơn vì nỗ lực của bạn @ richardhansen Tôi nghĩ rằng cố định bản thân mình bằng cách sử dụng mô-đun con. –