Skip to content

feat(git): submodule.recurse を有効化し効いていない ghq.shallow を削除する - #70

Merged
msageha merged 1 commit into
mainfrom
feat/git-submodule-recurse
Aug 24, 2026
Merged

feat(git): submodule.recurse を有効化し効いていない ghq.shallow を削除する#70
msageha merged 1 commit into
mainfrom
feat/git-submodule-recurse

Conversation

@msageha

@msageha msageha commented Aug 24, 2026

Copy link
Copy Markdown
Owner

概要

サブモジュールを持つリポジトリで --recurse-submodules を都度指定しなくて済むよう、global gitconfig に submodule.recurse = true を追加する。

あわせて、同ファイルにあった ghq.shallow = true を削除する。この設定は ghq に読まれておらず、実際には無視されていた。

変更内容

  • home/dot_config/git/config.tmpl[submodule] recurse = true を追加
  • home/dot_config/git/config.tmpl から [ghq] shallow = true を削除

ghq.shallow が効いていない根拠

ghq 1.10.1 (手元) で実測した結果、global に ghq.shallow = true がある状態でもフラグなしでは shallow clone にならない。

.git/shallow rev-list --count HEAD
フラグなし (gitconfig のみ) 無し 3
--shallow 明示 有り 1

同一リポジトリ (github.com/octocat/Hello-World) を GHQ_ROOT だけ変えて clone した結果。

ソース側も一致する。commands.go のフラグ定義は &cli.BoolFlag{Name: "shallow", Usage: "Do a shallow clone"}Sources / EnvVars を持たず、cmd_get.godoGetshallow: cmd.Bool("shallow") と CLI フラグを読むだけで gitconfig を参照しない。ghq が gitconfig から読むのは ghq.root / ghq.user / ghq.completeUser / ghq.defaultHost / ghq.<url>.vcs / ghq.<url>.root の 6 キーのみで、README.adoc の CONFIGURATION 節にも ghq.shallow の記載はない。

shallow clone が必要なときは ghq get --shallow、push できない等の制約を避けたい場合は ghq get --partial blobless を都度指定する。

関連 Issue

なし

動作確認

  • mise run pre-commit が通った
  • mise run test が通った (sandbox 外で 46/46 pass)
  • mise run dry-run で意図した差分のみであることを確認した → 後述の理由により対象を限定して実行

mise run dry-run--verbose 付きで全対象を走らせるため、~/.codex/.env 等の secret ファイルが差分に含まれると実値が出力に載る。そのため chezmoi apply --dry-run --verbose ~/.config/git/config と対象を絞って実行した。

apply 後の実環境も確認済み。

$ git config --global --get submodule.recurse
true
$ git config --global --get ghq.shallow
$ echo $?
1
$ git config --global --get ghq.root
~/Works/src

チェックリスト

  • テストを追加・更新した (gitconfig の宣言的な設定変更のためテストなし)
  • ドキュメントを更新した (該当なし)
  • 破壊的変更が含まれる場合、その影響範囲を明記した

補足情報

submodule.recurse = true の影響範囲は git help config の記述どおり checkout / fetch / grep / pull / push / read-tree / reset / restore / switch で、clone と ls-files は対象外。

注意すべきは push で、git help push に「push.recurseSubmodules は default、ただし submodule.recurse が set されている場合は true = on-demand として扱う」とある。つまりこの変更により、push 時にサブモジュール側の未 push コミットがあれば一緒に push されるようになる。この挙動を避けたい場合は push.recurseSubmodules = no の併記で打ち消せるが、今回は入れていない。

一時的に無効化したい場合は git -c submodule.recurse=0 <command> を使う。

サブモジュールを持つリポジトリで checkout / fetch / pull のたびに
--recurse-submodules を指定しなくて済むよう submodule.recurse を有効にする。
clone と ls-files は対象外。push では push.recurseSubmodules の既定として
作用し、true は on-demand 相当に解釈される。

あわせて ghq.shallow を削除する。ghq が gitconfig から読むのは ghq.root /
ghq.user / ghq.completeUser / ghq.defaultHost / ghq.<url>.vcs / ghq.<url>.root
のみで、shallow は CLI フラグ (--shallow) 専用のためこの設定は無視されていた。
実測でも gitconfig のみでは shallow clone にならないことを確認済み。
@msageha
msageha enabled auto-merge (squash) August 24, 2026 10:32
@msageha
msageha merged commit de9a68b into main Aug 24, 2026
8 checks passed
@msageha
msageha deleted the feat/git-submodule-recurse branch August 24, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant