:octocat: ๐ ๐ Automation to synchronise updates from a template repository to all associated repositories. Enhances maintainability, consistency and governance across the NHS England's GitHub projects.
If there are no files marked for deletion, $to_delete isn't empty, it contains a single newline. That means the while loop evaluates once, with rm expanded to rm -rf $dest_dir/. That (rather obviously) breaks subsequent steps. If somehow we'd managed to get to this point with $dest_dir set to an empty string too, that would be... uh... bad, but we're also not asserting there's anything in that variable in this function.
I think the right thing to do is to check for this in the while loop with an if [ ! -z "$file" ]; then... just for robustness, but it might be that we want to tweak the jq invocation somehow too.