Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
resync.sh: Add logic to deal with dirty repos
Browse files Browse the repository at this point in the history
  • Loading branch information
RisenID committed Nov 9, 2024
1 parent a95a3b5 commit d2277bf
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions resync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euo pipefail
WORKDIR="/home/sketu/rising"
OUTPUT_FILE="/tmp/repo_sync_output.txt"
SYNC_STATUS="/tmp/sync.txt"
DIRTY_REPOS="/tmp/failed.txt"
FAIL=0
DELETED_REPOS_FILE="$WORKDIR/deleted_repositories.txt"
STABLE_REPO_URL="https://github.com/RisingTechOSS/android"
Expand Down Expand Up @@ -40,6 +41,8 @@ init_repo() {

sync_repos() {
log "Syncing repositories..."
rm -f /tmp/failed.txt
rm -f /tmp/sync.txt
find "$WORKDIR/.repo" -name '*.lock' -delete
repo sync -c -j"$(nproc --all)" --force-sync --no-clone-bundle --no-tags --prune | tee "$SYNC_STATUS"
if grep -q error: "$SYNC_STATUS"; then
Expand All @@ -66,15 +69,36 @@ delete_failing_repos() {
fi
}

delete_dirty_repos() {
log "Checking for failing repositories..."
# grep -w "error: checkout" "$SYNC_STATUS"
grep -w "Cannot remove project: uncommitted changes are present." "$SYNC_STATUS" >> "$DIRTY_REPOS"
if [ -n "$DIRTY_REPOS" ]; then
log "Deleting dirty repositories:"
sed -i s/error\: //g "$DIRTY_REPOS"
sed -i s/\: Cannot remove project\: uncommitted changes are present\.//g "$DIRTY_REPOS"
echo "$DIRTY_REPOS" | while read -r repo; do
log "Deleting repository: $repo"
echo "$repo" >> "$DELETED_REPOS_FILE"
rm -rf "$WORKDIR/$repo" "$WORKDIR/.repo/projects/$repo.git"
done
else
log "No failing repositories found"
fi
}

perform_sync() {
if [ $FAIL=1 ]; then
if [[ ( $FAIL == 1 ) || ( $FAIL == 2 ) ]]; then
delete_failing_repos
delete_dirty_repos
log "Re-attempting sync after deleting failing repositories"
sync_repos
if [ $FAIL=2 ]; then
if [ "$FAIL" -eq "2" ]; then
log "Error: repo sync failed even after deleting failing repositories"
exit 1
fi
else
sync_repos
fi
}

Expand Down

0 comments on commit d2277bf

Please sign in to comment.