Submoduleで管理しているHugoのThemeが更新されているので追随させる(git一般の話)

Posted by utimukat55 on Thursday, November 7, 2019

TOC

HugoのThemeも更新するよね

このblogはHugoで作成されていて、テーマは自分で選んだものをgit submoduleで参照している形になります。そして、submoduleは参照先が更新されても手元は一切更新されないことを知りました。という事は、

【手動で更新するように仕向けないと元の更新内容が反映されない】

んですね。安定志向です。

このblogで使っているテーマはどないでしょうか

Hugoのコンテンツ自体はGitLabでしているので、インターネットに繋がっていればどこからでもcloneして同じものを利用可能です。テーマはこちらを使っています。

GitHub - zhaohuabing/hugo-theme-cleanwhite: A clean, elegant blog theme for hugo

A clean, elegant blog theme for hugo. Contribute to zhaohuabing/hugo-theme-cleanwhite development by creating an account on GitHub.

では、まっさらからcloneしたところにあるリポジトリのsubmodule設定を見てみましょう。submoduleとして取得したディレクトリの下でgit logを実行します1

ro_followup/themes/hugo-theme-cleanwhite$ git log --oneline
722b6c6 (HEAD) Don't push pages to Baidu unless Baidu analytics is enabled
8bb6365 Remove google and baidu verification codes
c674a8b Merge pull request #46 from markaldridge/patch-1
7621b6f Merge pull request #45 from merikan/showtoc_as_sitewide
c874dd2 Added site params for about_me
9ac8190 allow to override the default behaviour for showtoc with sitewide param in config.toml
bfab752 update license year

次に、submoduleとして取り込んでいる元を別の場所にgit cloneして同じようにgit logしてみます。

$ git clone https://github.com/zhaohuabing/hugo-theme-cleanwhite.git
$ cd hugo-theme-cleanwhite/
hugo-theme-cleanwhite$ git log --oneline
d094898 (HEAD -> master, origin/master, origin/HEAD) fix navbar height issue in smart screens
10a4c96 Aligin figure caption to center
3b47379 Duplicated scroll bar and stuck scrolling #60
75dada4 (tag: 1.0.0) Photo gallery shortcode
ef2aef8 Remove warning messages
c93ea6d Merge pull request #59 from merikan/add_custom_js_and_css
e606030 Merge branch 'master' into add_custom_js_and_css
af707cf Merge pull request #58 from merikan/add_lastmod
ac0c2e8 Merge pull request #57 from JackKuo-tw/highlightjs
68a0346 Merge pull request #56 from bionade24/feature/social-buttons
e989207 add support for custom js and css
82f2e87 add Last Modified on information
6c81594 Add highlight.js conf
7c40425 Added icons for gitlab, git, stackoverflow, reddit, mastodon and keybase
722b6c6 Don't push pages to Baidu unless Baidu analytics is enabled
8bb6365 Remove google and baidu verification codes

全然ちゃうやないかい…ていうか1.0になってるんや…14回もcommitされてるで…

submoduleが紐づいているCommitIDを確認する

gitリポジトリで管理しているsubmoduleがどのCommitIDに紐づけられているかは、gitリポジトリ内でgit submoduleを実行すると表示されます。

ro_followup$ git submodule
 722b6c6c91fdd3255fc79887d7bb196640a61bef themes/hugo-theme-cleanwhite (heads/master)

参照しているCommitIDを更新する

差分がある事を確認したら、今回はとりあえず最新にしてみて手元で表示を確認します。

$ git submodule update --remote
remote: Enumerating objects: 53, done.
remote: Counting objects: 100% (53/53), done.
remote: Total 85 (delta 53), reused 53 (delta 53), pack-reused 32
Unpacking objects: 100% (85/85), done.
From https://github.com/zhaohuabing/hugo-theme-cleanwhite
   722b6c6..d094898  master     -> origin/master
 * [new tag]         1.0.0      -> 1.0.0
Submodule path 'themes/hugo-theme-cleanwhite': checked out 'd094898375068812b1763366d548c746bf604fae'

手元が更新されていることを確認

git statusで参照先が更新されている事を確認します。(関係ないところは削除しています)

ro_followup$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   themes/hugo-theme-cleanwhite (new commits)

modifiedをおもむろにgit addします(ディレクトリ名をそのまま指定します)

$ git add themes/hugo-theme-cleanwhite
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   themes/hugo-theme-cleanwhite

後はいつも通りgit commit git pushで更新されます。このテーマに限って言えば発行日と更新日が両方とも出力されるようになりましたね。めでたしめでたし。


  1. --onelineを付けると1コミット1行になるので見やすいですね [return]

comments powered by Disqus

See Also