Skip to content

Commit 4826d91

Browse files
committed
fix(git_pull): fix extglob syntax and undefined OLD_COMMIT variable
- 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
1 parent e56d47a commit 4826d91

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

git_pull/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 8.0.2
4+
- Fix broken extglob pattern for restoring non-YAML files after clone
5+
- Fix undefined OLD_COMMIT variable after fresh clone
6+
37
## 8.0.1
48
- Fix bashio warn(ing) logger usage breaking deployment keys
59

git_pull/data/run.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ function git-clone {
5656
bashio::log.info "[Info] Start git clone"
5757
git clone "$REPOSITORY" /config || bashio::exit.nok "[Error] Git clone failed"
5858

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

6264
# try to copy secrets file back
63-
cp "${BACKUP_LOCATION}/secrets.yaml" /config 2>/dev/null
65+
cp "${BACKUP_LOCATION}/secrets.yaml" /config 2>/dev/null || true
6466
}
6567

6668
function check-ssh-key {
@@ -116,6 +118,9 @@ fi
116118
}
117119

118120
function git-synchronize {
121+
# Initialize OLD_COMMIT (will remain empty if this is a fresh clone)
122+
OLD_COMMIT=""
123+
119124
# is /config a local git repo?
120125
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
121126
bashio::log.warning "[Warn] Git repository doesn't exist"
@@ -173,6 +178,19 @@ function git-synchronize {
173178

174179
function validate-config {
175180
bashio::log.info "[Info] Checking if something has changed..."
181+
182+
# Handle fresh clone case where OLD_COMMIT was never set
183+
if [ -z "$OLD_COMMIT" ]; then
184+
bashio::log.info "[Info] Fresh clone detected, validating configuration..."
185+
if ! bashio::core.check; then
186+
bashio::log.error "[Error] Fresh clone configuration does not pass validation!"
187+
else
188+
bashio::log.info "[Info] Fresh clone configuration is valid"
189+
fi
190+
# Skip restart logic on fresh clone (no previous state to compare)
191+
return
192+
fi
193+
176194
# Compare commit ids & check config
177195
NEW_COMMIT=$(git rev-parse HEAD)
178196
if [ "$NEW_COMMIT" == "$OLD_COMMIT" ]; then

0 commit comments

Comments
 (0)