From 2f0a95674cf3b5cb00f41e60dd676eeb025e78d8 Mon Sep 17 00:00:00 2001 From: Kenji Morishige Date: Wed, 22 Apr 2026 14:44:19 -0500 Subject: [PATCH] Fix: Resolve relative path issue in backup script git operations - Convert backup file path to absolute path before git add/commit - Fixes 'pathspec did not match any files' error when using ../ - Use absolute_backup_path consistently in commit_to_git() - Tested successfully: backups now commit to git without errors --- .../scripts/backup-pfsense-config.sh | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pfsense.home.arpa/scripts/backup-pfsense-config.sh b/pfsense.home.arpa/scripts/backup-pfsense-config.sh index 27aa35b..6713886 100755 --- a/pfsense.home.arpa/scripts/backup-pfsense-config.sh +++ b/pfsense.home.arpa/scripts/backup-pfsense-config.sh @@ -212,15 +212,17 @@ validate_config() { commit_to_git() { log_info "Committing backup to git repository..." - local relative_path - relative_path=$(git -C "${REPO_ROOT}" ls-files --full-name "${BACKUP_FILE}" 2>/dev/null || echo "${BACKUP_FILE}") + # Convert to absolute path to avoid issues with relative paths containing ../ + local absolute_backup_path + absolute_backup_path="$(cd "$(dirname "${BACKUP_FILE}")" && pwd)/$(basename "${BACKUP_FILE}")" - if [[ -z "${relative_path}" ]]; then - relative_path="${BACKUP_FILE}" + if [[ ! -f "${absolute_backup_path}" ]]; then + log_error "Backup file not found at: ${absolute_backup_path}" + return 1 fi - # Add the backup file to git - if git -C "${REPO_ROOT}" add "${BACKUP_FILE}"; then + # Add the backup file to git using absolute path + if git -C "${REPO_ROOT}" add "${absolute_backup_path}"; then log_success "Added backup to git staging area" else log_error "Failed to add backup to git" @@ -234,9 +236,9 @@ commit_to_git() { # Get configuration summary from XML local vlan_count - vlan_count=$(grep -c '' "${BACKUP_FILE}" 2>/dev/null || echo "unknown") + vlan_count=$(grep -c '' "${absolute_backup_path}" 2>/dev/null || echo "0") local rule_count - rule_count=$(grep -c '' "${BACKUP_FILE}" 2>/dev/null || echo "unknown") + rule_count=$(grep -c '' "${absolute_backup_path}" 2>/dev/null || echo "0") # Enhanced commit message with details local detailed_msg="${commit_msg} @@ -247,7 +249,7 @@ Contains: - Backup timestamp: ${TIMESTAMP} File: $(basename "${BACKUP_FILE}") -SHA256: $(shasum -a 256 "${BACKUP_FILE}" | awk '{print $1}') +SHA256: $(shasum -a 256 "${absolute_backup_path}" | awk '{print $1}') " # Commit the backup