Skip to content

fix(ohmyzsh): unshallow clone after install so omz update works - #36

Merged
gitricko merged 1 commit into
mainfrom
fix/ohmyzsh-shallow-clone-update
Aug 16, 2026
Merged

fix(ohmyzsh): unshallow clone after install so omz update works#36
gitricko merged 1 commit into
mainfrom
fix/ohmyzsh-shallow-clone-update

Conversation

@gitricko

Copy link
Copy Markdown
Owner

Problem

When users run omz update (the prompt that fires when a new omz release is detected), it fails with:

[oh-my-zsh] Would you like to update? [Y/n] Y
Updating Oh My Zsh
error: Could not read <hash>
error: could not parse commit <hash>
There was an error updating. Try again later?

Root cause

The omz installer script (ohmyzsh/tools/install.sh line 317) does:

git fetch --depth=1 origin

So ~/.oh-my-zsh ships as a shallow clone. omz update later runs git pull, which needs to fetch the parent commits of the local tip to do the merge. Those parents are outside the depth-1 boundary, and once GitHub GCs them on origin (or force-pushes rewrite history), they're permanently unreachable — hence the "Could not read" error pointing at commit hashes that are merge tips' parents.

Fix

After the unattended install, run git fetch --unshallow origin to convert the depth-1 clone into a full clone. Guarded with:

  • if [ -d "$HOME/.oh-my-zsh/.git" ] — only runs if omz actually installed
  • 2>/dev/null || true — never blocks the boot path on network/partial-state issues

Diff

     runuser -l abc -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended'

+    # The omz install.sh does `git clone --depth=1`, which makes `omz update`
+    # fail later with "Could not read <hash>" when parents get GC'd on origin.
+    # Unshallow to a full clone so future updates work reliably.
+    if [ -d "$HOME/.oh-my-zsh/.git" ]; then
+        runuser -l abc -c 'cd "$HOME/.oh-my-zsh" && git fetch --unshallow origin 2>/dev/null || true'
+    fi
+
     ZSHRC="$HOME/.zshrc"

Cost

  • Image size: +~5-10 MB (full omz history is ~80 MB vs ~3 MB depth-1)
  • Build time: +~10-20s (full git fetch vs depth-1)
  • Runtime: omz update works reliably for the lifetime of the container

Test plan

  • Rebuild image, confirm omz version shows is_repo: true, is_clean: ...
  • git -C ~/.oh-my-zsh rev-parse --is-shallow-repositoryfalse
  • Trigger omz update — should complete without "Could not read" errors

The omz install.sh always does git clone --depth=1, which makes
later 'omz update' invocations fail with:

  error: Could not read <hash>
  error: could not parse commit <hash>
  There was an error updating. Try again later?

when the parent commits of merge tips get GC'd on the remote
(or are otherwise unreachable from the depth-1 boundary).

Fix: run 'git fetch --unshallow origin' right after the unattended
install, with a directory guard and || true so it never breaks
the boot path.
Copilot AI lite review requested due to automatic review settings August 16, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitricko
gitricko merged commit d10a2b5 into main Aug 16, 2026
4 checks passed
@gitricko
gitricko deleted the fix/ohmyzsh-shallow-clone-update branch August 16, 2026 14:28
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.

2 participants