From 1af213a95a8279497bdabf59d4a3dc0c88fbf3e1 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 26 Sep 2024 14:20:37 +0200 Subject: [PATCH] handle locally existing branches --- bin/git-pull-and-if-origin-changed-run-tests | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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