diff options
| -rwxr-xr-x | rclone-ide | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -125,10 +125,36 @@ def build_cmd_config() -> str: return f"--config={config_file}" -def build_cmd_exclude() -> List[str]: +def build_cmd_exclude(config: Mapping[str, Any]) -> List[str]: """Build the various exclude option parts for the rclone command.""" + + cmd = [] + local_path = build_cmd_local_path(config) + + # add default exclude patterns + default_exclude_patterns = config.get("rclone_ide_default_exclude_patterns", "").split(",") + if default_exclude_patterns == [""]: + default_exclude_patterns = [".git/", ".gitignore", ".rcloneignore"] + + for pattern in default_exclude_patterns: + cmd.append(f"--exclude={pattern}") + + # add .gitignore patterns + gitignore = os.path.join(local_path, ".gitignore") + if os.path.exists(gitignore): + cmd.append(f"--exclude-from={gitignore}") + + process = subprocess.run(["git", "config", "--get", "core.excludesfile"], capture_output=True, text=True) + gitignore_global = os.path.expanduser(process.stdout.strip()) + if gitignore_global and os.path.exists(gitignore_global): + cmd.append(f"--exclude-from={gitignore_global}") + + # add .rcloneignore patterns + rcloneignore = os.path.join(local_path, ".rcloneignore") + if os.path.exists(rcloneignore): + cmd.append(f"--exclude-from={rcloneignore}") - return "" + return cmd def build_cmd_logging(log_level: str = "INFO") -> List[str]: @@ -224,6 +250,7 @@ def command_copy(options: Mapping[str, Any]) -> None: local_directory_path, ).rstrip("/"), build_cmd_config(), + *build_cmd_exclude(remote_config["config"]), *build_cmd_logging(), ] @@ -254,6 +281,7 @@ def command_copy_file(options: Mapping[str, Any]) -> None: os.path.dirname(local_file_path), ), build_cmd_config(), + *build_cmd_exclude(remote_config["config"]), *build_cmd_logging(), ] |
