diff --git a/bin/git-pull-and-if-origin-changed-run-tests b/bin/git-pull-and-if-origin-changed-run-tests index f955323d..3a8476ef 100755 --- a/bin/git-pull-and-if-origin-changed-run-tests +++ b/bin/git-pull-and-if-origin-changed-run-tests @@ -1,36 +1,52 @@ #!/bin/bash -# get the current branch name -BRANCH=$(git rev-parse --abbrev-ref HEAD) +# Configuration: Set the remote repository name and check interval +BUILD_CMD="gw-test" # Placeholder for the build command + +# Fetch the latest updates from the origin +git fetch origin + +# Keep track of local branches at the start +local_branches=$(git branch -r | sed 's/origin\///') while true; do + echo "Checking for new branches..." - # get the latest commit hashes from origin and local - git fetch origin - LOCAL=$(git rev-parse HEAD) - REMOTE=$(git rev-parse origin/$BRANCH) + # Fetch the latest updates from the origin + git fetch origin - # check if the local branch differs from the remote branch - if [ "$LOCAL" != "$REMOTE" ]; then - echo "local $LOCAL differs from remote $REMOTE => pulling changes from origin" - git pull origin $BRANCH + # List the remote branches after fetching and compare with local branches + new_branches=$(git branch -r | sed 's/origin\///' | grep -Fxv "$local_branches") - # run the command - echo "Running ./gradlew test" - source .aliases # only variables, aliases are not expanded in scripts - ./gradlew test - fi + if [ -n "$new_branches" ]; then + for branch in $new_branches; do + echo "New branch detected: $branch" - # wait 10s with a little animation - echo -e -n " waiting for changes (/) ..." - sleep 2 - echo -e -n "\r\033[K waiting for changes (-) ..." - sleep 2 - echo -e -n "\r\033[K waiting for changes (\) ..." - sleep 2 - echo -e -n "\r\033[K waiting for changes (|) ..." - sleep 2 - echo -e -n "\r\033[K waiting for changes ( ) ... " - sleep 2 - echo -e -n "\r\033[K" + # Check out the new branch locally + git checkout -b "$branch" "origin/$branch" + + # Placeholder for build process (replace $BUILD_CMD with actual build steps) + echo "Building branch $branch..." + # eval "$BUILD_CMD" + + # Update the local branch list + local_branches="$local_branches $branch" + done + else + echo "No new branches found." + fi + + # wait 10s with a little animation + echo -e -n " waiting for changes (/) ..." + sleep 2 + echo -e -n "\r\033[K waiting for changes (-) ..." + sleep 2 + echo -e -n "\r\033[K waiting for changes (\) ..." + sleep 2 + echo -e -n "\r\033[K waiting for changes (|) ..." + sleep 2 + echo -e -n "\r\033[K waiting for changes ( ) ... " + sleep 2 + echo -e -n "\r\033[K checking for changes" done +