========================== go-gh-pages ========================== * cli のたたき台として `gh-pages `_ を Go で実装する * go-git を使って git を操作すると pure go になっておしゃれ .. note:: go-git で同様の操作ができるかどうかは要確認 go-gh-pages ========================== * あるディレクトリにgit cloneする。 .. code-block:: bash git clone 'https://github.com/d-tsuji/test-go-gh-pages.git' tempDir --branch xxx --single-branch --origin origin --depth 1 ブランチが存在しない場合はエラーになるので、その場合はオプションを変更して再度 git clone する。 .. code-block:: bash git clone 'https://github.com/d-tsuji/test-go-gh-pages.git' tempDir --origin origin * リポートリポジトリの URL を取得する .. code-block:: bash git config --get remote.origin.url * アントラッキングなファイルを強制的に削除する .. code-block:: bash git clean -f -d # ちなみに git のオプション的には以下のようになっている。 # git clean -h # usage: git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x | -X] [--] ... # # -q, --quiet do not print names of files removed # -n, --dry-run dry run # -f, --force force # -i, --interactive interactive cleaning # -d remove whole directories # -e, --exclude # add to ignore rules # -x remove ignored files, too # -X remove only ignored files * リモートリポジトリから fetch する * リモートリポジトリから checkout する リモートリポジトリにターゲットのブランチが存在するかチェックする .. code-block:: bash git ls-remote --exit-code . origin/gh-pages リモートに存在しない場合はローカルに ``--orphan`` オプションを付けてブランチを作成する .. code-block:: bash git checkout --orphan gh-pages リモートに存在する場合はローカルで初期化する .. code-block:: bash git clean -f -d git reset --hard origin/gh-pages ちなみに ``git checkout`` のオプションは以下。 .. code-block:: bash #git checkout -h #usage: git checkout [] #or: git checkout [] [] -- ... # # -b create and checkout a new branch # -B create/reset and checkout a branch # -l create reflog for new branch # --guess second guess 'git checkout ' (default) # --overlay use overlay mode (default) # -q, --quiet suppress progress reporting # --recurse-submodules[=] # control recursive updating of submodules # --progress force progress reporting # -m, --merge perform a 3-way merge with the new branch # --conflict