Skip to content

git_pull: Fix data loss of .storage and unrelated local files on fresh clone#4356

Open
BrianTillman wants to merge 1 commit intohome-assistant:masterfrom
BrianTillman:fix/git-pull-extglob-syntax
Open

git_pull: Fix data loss of .storage and unrelated local files on fresh clone#4356
BrianTillman wants to merge 1 commit intohome-assistant:masterfrom
BrianTillman:fix/git-pull-extglob-syntax

Conversation

@BrianTillman
Copy link

@BrianTillman BrianTillman commented Jan 29, 2026

Summary

This commit fixes two issues in the git_pull addon:

Extglob syntax: Fix broken extglob copy syntax that prevented non-YAML files from being restored after git clone.

  • The original line cp "${BACKUP_LOCATION}" "!(*.yaml)" was syntactically incorrect - it treated the backup location as a source file and the extglob pattern as a separate argument.
  • Additionally, extglob patterns like !(*.yaml|*.yml) are parsed at script load time, before shopt -s extglob executes. Fixed by wrapping the cp command in eval to delay pattern parsing until runtime.
  • Enables dotglob to preserve hidden directories like .storage/
  • Enables nullglob and adds || true for graceful handling when no files match

OLD_COMMIT unbound variable: Caused the process to fail on fresh git clones.

  • When git-clone runs (fresh clone), OLD_COMMIT was never set, causing validate-config to fail. Fixed by initializing OLD_COMMIT="" and adding fresh clone handling that validates config without restart logic.

Fixes #3547 - Users reported that .storage/ and custom_components/ folders were being deleted after fresh clone because the backup restore silently failed.

Test plan

  • Fresh clone preserves local non-YAML files (deps/, *.db)
  • Fresh clone preserves local secrets.yaml
  • Fresh clone preserves hidden directories (.storage/)
  • Fresh clone validates config without errors
  • .yml files come from git (not restored from backup)

This PR was validated using a dedicated test fixtures repository:

Summary by CodeRabbit

  • Bug Fixes
    • Fixed failures restoring files after cloning repositories.
    • Resolved an initialization error during fresh clones.
    • Improved backup restoration to correctly exclude configuration files.
    • Made backup handling tolerant of missing backup files.
    • Ensured hidden dotfiles are preserved when restoring backups.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Fixes two issues: restores non-YAML backup files correctly during git-clone by fixing the extglob copy logic, and prevents an undefined OLD_COMMIT on fresh clones by initializing it and adding a fresh-clone validation path that avoids restart logic.

Changes

Cohort / File(s) Summary
Changelog
git_pull/CHANGELOG.md
Add version 8.0.2 entry documenting two fixes: extglob pattern for restoring non-YAML files and undefined OLD_COMMIT on fresh clone.
Runtime script
git_pull/data/run.sh
Fix extglob-enabled copy to exclude YAML/YML when restoring backups (use eval and preserve dotfiles); make secrets.yaml restore tolerant to missing file; initialize OLD_COMMIT in git-synchronize; add fresh-clone path in validate-config to skip restart flow when OLD_COMMIT is empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: preventing data loss of .storage and unrelated local files during fresh git clones, which is the core issue addressed in the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #3547 by fixing extglob pattern handling for backup restoration and initializing OLD_COMMIT to prevent crashes on fresh clones, preserving .storage, custom_components, and other non-YAML files.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the reported issues: extglob/glob handling in git-clone, secrets.yaml error tolerance, OLD_COMMIT initialization in git-synchronize, and validation logic for fresh clones.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

cp "${BACKUP_LOCATION}" "!(*.yaml)" /config 2>/dev/null
# try to copy non-yaml files back (use eval to avoid parse-time extglob error)
shopt -s extglob nullglob dotglob
eval 'cp -r "${BACKUP_LOCATION}"/!(*.yaml|*.yml) /config 2>/dev/null' || true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it would be better to use find here?

Copy link
Author

Choose a reason for hiding this comment

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

Great suggestion! I considered both approaches:

find alternative:

find "${BACKUP_LOCATION}" -maxdepth 1 -mindepth 1 ! -name "*.yaml" ! -name "*.yml" -exec cp -r {} /config/ \; 2>/dev/null || true

Trade-offs:

  • find is more portable (POSIX) and doesn't require shell option toggling
  • eval + extglob is a common bash pattern and keeps it consistent with the existing rm -rf /config/{,.[!.],..?}* pattern on line 53

Fixed the bug in place rather than introducing a different approach - easier to review and less risk. Happy to switch to find if preferred, or follow up with additional PRs to refactor the backup and restore functionality.

- Use eval to wrap extglob pattern, avoiding parse-time syntax error
- Initialize OLD_COMMIT variable and handle fresh clone case in validate-config
- Restore subdirectories and hidden files from backup
@BrianTillman BrianTillman force-pushed the fix/git-pull-extglob-syntax branch from 600e47b to 4826d91 Compare February 1, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git pull constantly clears directory including .storage folder

2 participants