diff --git a/bin/git-pull-and-if-origin-changed-run-tests b/bin/git-pull-and-if-origin-changed-run-tests index ae5d7fd1..7e98b8ac 100755 --- a/bin/git-pull-and-if-origin-changed-run-tests +++ b/bin/git-pull-and-if-origin-changed-run-tests @@ -10,8 +10,14 @@ while true; do if [ -n "$branch_with_new_commits" ]; then echo "checking out branch: $branch_with_new_commits" - echo "git checkout -b \"$branch_with_new_commits\" \"origin/$branch_with_new_commits\"" - git checkout -b "$branch_with_new_commits" "origin/$branch_with_new_commits" + if git show-ref --quiet --heads "$branch_with_new_commits"; then + echo "Branch $branch_with_new_commits already exists. Checking it out and pulling latest changes." + git checkout "$branch_with_new_commits" + git pull origin "$branch_with_new_commits" + else + echo "Creating and checking out new branch: $branch_with_new_commits" + git checkout -b "$branch_with_new_commits" "origin/$branch_with_new_commits" + fi echo "building ..." ./gradlew test