Skip to content

Instantly share code, notes, and snippets.

@ojura
Created January 24, 2018 09:37
Show Gist options
  • Save ojura/92362f2d1f517ca52d8effbbbcde5056 to your computer and use it in GitHub Desktop.
Save ojura/92362f2d1f517ca52d8effbbbcde5056 to your computer and use it in GitHub Desktop.
#!/bin/bash
SOURCE_REPOS="cartographer cartographer_ros root:"
TARGET_REPO="cartographer_combined"
function update_repo() {
SOURCE=$(echo $1 | sed -E 's/:.*//')
cd $SOURCE
FIRST_RUN=$2
if [[ $FIRST_RUN = "true" ]]; then echo "First run: $FIRST_RUN."; fi
OLD_HEAD=$(git rev-parse master)
#git remote update | grep -v "Fetching origin"
git pull origin master 2>&1 | grep -v -E "^From" | grep -v "FETCH_HEAD" | grep -v "Already up-to-date."
NEW_HEAD=$(git rev-parse master)
cd ..
if [[ "$OLD_HEAD" != "$NEW_HEAD" || $FIRST_RUN = "true" ]]; then
if [[ "$OLD_HEAD" != "$NEW_HEAD" ]]; then
echo "Updated $SOURCE!"
echo "Old head: $OLD_HEAD"
echo "New head: $NEW_HEAD"
fi
cd "$TARGET_REPO"
(cd ..; git-stitch-repo $SOURCE_REPOS) | git fast-import --force --quiet
git update-ref -d refs/heads/master
BRANCHES_SORTED=$(git branch --sort=-committerdate | sed -E "s/[ *]+//g")
NEWEST_BRANCH=$(echo "$BRANCHES_SORTED" | head -n 1)
echo "Newest branch is $NEWEST_BRANCH"
ALL_BRANCHES=$(echo "$BRANCHES_SORTED" | tr '\n' ' ')
git update-ref refs/heads/master $NEWEST_BRANCH
git branch -D $ALL_BRANCHES
git push origin --force
cd ..
fi
}
# First run, always stitches & pushes.
update_repo $(echo "$SOURCE_REPOS" | cut -f1 -d' ') true
while true; do
date
for repo in $SOURCE_REPOS; do
if [[ "$repo" != "root:" ]]; then
update_repo $repo false
fi
done
sleep 300
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment