Skip to content

Instantly share code, notes, and snippets.

@sounddrill31
Last active April 19, 2024 06:57
Show Gist options
  • Save sounddrill31/a72eef2c3a495c16433ce8f653859a09 to your computer and use it in GitHub Desktop.
Save sounddrill31/a72eef2c3a495c16433ce8f653859a09 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <repository_url> <branch_name>"
exit 1
fi
repo_url="$1"
branch_name="$2"
# Clone the repository
rm -rf repo || true
git clone "$repo_url" -b "$branch_name" repo
# Get XML paths from.repo/manifests
paths_1=$(find .repo/manifests -type f -name "*.xml" -exec grep -oP '(?<=<project path=")[^"]+' {} \;)
# Get XML paths from repo
paths_2=$(find repo -type f -name "*.xml" -exec grep -oP '(?<=<project path=")[^"]+' {} \;)
# Remove directories that are not present in the manifest
for path in $paths_1; do
if ! grep -q "$path" <<< "$paths_2"; then
echo "Removing $path"
rm -rf "$path"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment