Skip to content

Conversation

@JordanGoasdoue
Copy link

What issue type does this pull request address?

/kind enhancement

What does this pull request do? Which issues does it resolve?

Implements automatic recovery for git dependencies when git pull fails due to corrupted cache state or rewritten history.

Problem:

Git dependency caches can become invalid and cause git pull to fail, requiring manual deletion of ~/.devspace/dependencies/<hash>:

Common scenarios:

  1. Rewritten history on shared catalogs (primary use case):

    • When maintaining a shared catalog repository, developers use git commit --amend or force-push while iterating on feature branches
    • The cache becomes invalid because it references commits that no longer exist in the remote history
    • Git pull fails with various errors depending on git version/config:
      fatal: Need to specify how to reconcile divergent branches
      fatal: refusing to merge unrelated histories
      error: Your local changes to the following files would be overwritten
      
    • Current behavior: DevSpace shows warnings and continues with stale cache, or fails entirely
    • Impact: Developers must either:
      • Manually delete ~/.devspace/dependencies/<hash> for every force-push
      • Pin to specific revisions (defeats the purpose of tracking a branch)
      • Accept stale versions until manual cleanup
  2. Other cache corruption scenarios:

    • Detached HEAD state: reference is not a tree
    • Corrupted refs: fatal: couldn't find remote ref
    • Interrupted git operations leaving incomplete metadata

Why git config isn't a solution:

  • Git pull config (pull.rebase, pull.ff) controls how to reconcile branches
  • But when history is rewritten (force-push), there's no way to reconcile - the old commits literally don't exist anymore
  • The only solution is to re-clone fresh, which users currently must do manually

Solution:

When git pull fails, automatically:

  1. Clone the repository to a temporary location
  2. Replace the old cache only if the new clone succeeds
  3. Log informative messages so users understand recovery is happening

Key benefits:

  • For catalog developers: Iterate freely with git commit --amend / force-push without breaking consumer projects
  • For all users: Automatic recovery from any git cache corruption without manual intervention
  • Safe fallback: If re-clone fails (network issues, repo deleted), keeps the old working version

Changes:

  • Added recloneDependency() function with atomic replacement strategy (clone to temp → replace on success)
  • Modified DownloadDependency() to catch pull failures and trigger auto-reclone
  • Added informative logging during recovery process

Please provide a short message that should be published in the DevSpace release notes

Git dependencies now automatically recover from corrupted cache or rewritten history by re-cloning when pull fails, eliminating the need to manually delete the dependency cache.

What else do we need to know?

Implementation Details

Atomic replacement strategy:

  • Clones to temporary directory (<path>.tmp-reclone) first
  • Replaces old cache only if clone succeeds
  • If re-clone fails, keeps the old cached version (principle: "better old working version than no version at all")

@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for devspace-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit b359069
🔍 Latest deploy log https://app.netlify.com/projects/devspace-docs/deploys/6968d0d88bf8470008276847

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