diff --git a/backend/app/arr/manager.py b/backend/app/arr/manager.py index 47be72d..05cd791 100644 --- a/backend/app/arr/manager.py +++ b/backend/app/arr/manager.py @@ -529,3 +529,35 @@ def run_import_for_config(config_row): 'total_successful': total_successful, 'sync_percentage': sync_percentage } + + +def check_active_sync_configs(): + """ + Check if there are any ARR configurations with non-manual sync methods. + Returns (has_active_configs, details) tuple. + """ + with get_db() as conn: + cursor = conn.execute(''' + SELECT id, name, sync_method, data_to_sync + FROM arr_config + WHERE sync_method != 'manual' + ''') + active_configs = cursor.fetchall() + + if not active_configs: + return False, None + + details = [] + for config in active_configs: + data_to_sync = json.loads( + config['data_to_sync'] if config['data_to_sync'] else '{}') + if data_to_sync.get('profiles') or data_to_sync.get( + 'customFormats'): + details.append({ + 'id': config['id'], + 'name': config['name'], + 'sync_method': config['sync_method'], + 'data': data_to_sync + }) + + return bool(details), details diff --git a/backend/app/git/branches/checkout.py b/backend/app/git/branches/checkout.py index 2eed401..f688dd7 100644 --- a/backend/app/git/branches/checkout.py +++ b/backend/app/git/branches/checkout.py @@ -2,12 +2,30 @@ import git import logging +from ...arr.manager import check_active_sync_configs logger = logging.getLogger(__name__) def checkout_branch(repo_path, branch_name): try: + # Check for active sync configurations first + has_active_configs, configs = check_active_sync_configs() + if has_active_configs: + error_msg = ( + "Cannot checkout branch while automatic sync configurations are active.\n" + "The following configurations must be set to manual sync first:\n" + ) + for config in configs: + error_msg += f"- {config['name']} (ID: {config['id']}, {config['sync_method']} sync)\n" + + logger.error(error_msg) + return False, { + "error": error_msg, + "code": "ACTIVE_SYNC_CONFIGS", + "configs": configs + } + logger.debug(f"Attempting to checkout branch: {branch_name}") repo = git.Repo(repo_path) diff --git a/backend/app/git/repo/unlink.py b/backend/app/git/repo/unlink.py index 9cd2f82..a2a3395 100644 --- a/backend/app/git/repo/unlink.py +++ b/backend/app/git/repo/unlink.py @@ -3,12 +3,30 @@ import os import shutil import logging from ...db import save_settings +from ...arr.manager import check_active_sync_configs logger = logging.getLogger(__name__) def unlink_repository(repo_path, remove_files=False): try: + # Check for active sync configurations first + has_active_configs, configs = check_active_sync_configs() + if has_active_configs: + error_msg = ( + "Cannot unlink repository while automatic sync configurations are active.\n" + "The following configurations must be set to manual sync first:\n" + ) + for config in configs: + error_msg += f"- {config['name']} (ID: {config['id']}, {config['sync_method']} sync)\n" + + logger.error(error_msg) + return False, { + "error": error_msg, + "code": "ACTIVE_SYNC_CONFIGS", + "configs": configs + } + logger.info( f"Starting unlink_repository with repo_path: {repo_path} and remove_files: {remove_files}" ) diff --git a/frontend/src/api/api.js b/frontend/src/api/api.js index 918d459..9234beb 100644 --- a/frontend/src/api/api.js +++ b/frontend/src/api/api.js @@ -305,7 +305,10 @@ export const unlinkRepo = async (removeFiles = false) => { }); return response.data; } catch (error) { - console.error('Error unlinking repository:', error); + if (error.response?.data) { + // Return the error response directly + return error.response.data; + } throw error; } }; diff --git a/frontend/src/components/settings/git/repo/RepoContainer.jsx b/frontend/src/components/settings/git/repo/RepoContainer.jsx index ad501f2..9a6d07d 100644 --- a/frontend/src/components/settings/git/repo/RepoContainer.jsx +++ b/frontend/src/components/settings/git/repo/RepoContainer.jsx @@ -140,12 +140,26 @@ const RepoContainer = ({settings, setSettings, fetchGitStatus, status}) => { Alert.success('Repository unlinked successfully'); setShowUnlinkModal(false); } else { - Alert.error(response.error || 'Failed to unlink repository'); + // Check if the error is a structured object + if ( + typeof response.error === 'object' && + response.error.error + ) { + Alert.error(response.error.error); + } else if (typeof response.error === 'string') { + Alert.error(response.error); + } else { + Alert.error('Failed to unlink repository'); + } } } catch (error) { - Alert.error( - 'An unexpected error occurred while unlinking the repository' - ); + if (error.response?.data?.error) { + Alert.error(error.response.data.error); + } else { + Alert.error( + 'An unexpected error occurred while unlinking the repository' + ); + } console.error('Error unlinking repository:', error); } finally { setLoadingAction('');