Skip to content

Conversation

ElleNajt
Copy link

@ElleNajt ElleNajt commented Aug 15, 2025

Fix: Update git submodules during package upgrades

Fixes #238

Problem

Straight.el runs git submodule update --init --recursive during initial clone but doesn't update submodules during package upgrades. When upstream repositories update submodule pointers, local submodules remain at old commits, causing repositories to appear dirty.

This addresses issue #238. Related issues include #502 and external reports like kaushalmodi/ox-hugo#346 where users encounter persistent submodule conflicts during upgrades.

Example

The gptel package uses a test submodule. After upstream updates the submodule pointer, doom upgrade prompts:

> Repository "gptel" has a dirty worktree:
    
       M test

         1) Abort
         2) Stash changes  
         3) Discard changes

Solution

Add git submodule update --init --recursive after merges in straight-vc-git--merge-from-remote-raw when .gitmodules exists.

Implementation

;; In straight-vc-git--merge-from-remote-raw:
(when (file-exists-p
       (expand-file-name ".gitmodules"
                         (straight--repos-dir local-repo)))
  (straight--process-output "git" "submodule" "update" "--init" "--recursive"))

Testing

Tested with both existing and new submodules:

Existing submodule scenario:

  • Before fix: Required manual "Discard changes" on every upgrade
  • After fix: Manual resolution once, then submodules stay in sync automatically

New submodule scenario:

  • Added test submodule to tracked repository
  • doom upgrade automatically initialized submodule without prompts
  • Updated submodule pointer to new commit
  • doom upgrade automatically synced to new commit without prompts

Fix successfully prevents submodule pointer mismatches for both scenarios.

No impact on repositories without submodules.

ElleNajt and others added 2 commits August 14, 2025 23:21
Addresses issue where repositories with submodules appear permanently
"dirty" after upgrades when the main repository updates its submodule
pointer but the local submodule remains at the old commit.

- Add submodule update logic in straight-vc-git--merge-from-remote-raw
- Only runs when .gitmodules exists (no performance impact otherwise)
- Fully backward compatible with existing configurations
- Follows existing straight.el patterns for git operations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@raxod502 raxod502 changed the base branch from main to develop August 15, 2025 22:30
@raxod502 raxod502 merged commit 341e01e into radian-software:develop Aug 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Repository management commands don't work with submodules
2 participants