Compare commits

...

7 Commits

Author SHA1 Message Date
Michael Hoennig
1af213a95a handle locally existing branches 2024-09-26 14:20:37 +02:00
Michael Hoennig
0675918362 fix branch recognition 2024-09-26 14:17:41 +02:00
Michael Hoennig
e8c4946111 explicitly call gradlew build 2024-09-26 14:12:03 +02:00
Michael Hoennig
086fb11436 echo checkout command 2024-09-26 14:09:44 +02:00
Michael Hoennig
e7558cdbe8 wait for branch with new commit 2024-09-26 13:59:13 +02:00
Michael Hönnig
c2ea66a87f some comment 2024-09-26 13:45:49 +02:00
Michael Hoennig
4eceb41ebc watch all branches for changes 2024-09-26 12:04:41 +02:00

View File

@ -1,23 +1,25 @@
#!/bin/bash #!/bin/bash
# waits for commits on any branch on origin, checks it out and builds it
# get the current branch name . .aliases
BRANCH=$(git rev-parse --abbrev-ref HEAD)
while true; do while true; do
echo "Checking for new commits on any branch ..."
# get the latest commit hashes from origin and local
git fetch origin git fetch origin
LOCAL=$(git rev-parse HEAD) branch_with_new_commits=`git fetch origin >/dev/null; git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads | grep '\[behind' | cut -d' ' -f1 | head -n1`
REMOTE=$(git rev-parse origin/$BRANCH)
# check if the local branch differs from the remote branch if [ -n "$branch_with_new_commits" ]; then
if [ "$LOCAL" != "$REMOTE" ]; then echo "checking out branch: $branch_with_new_commits"
echo "local $LOCAL differs from remote $REMOTE => pulling changes from origin" if git show-ref --quiet --heads "$branch_with_new_commits"; then
git pull origin $BRANCH 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
# run the command echo "building ..."
echo "Running ./gradlew test"
source .aliases # only variables, aliases are not expanded in scripts
./gradlew test ./gradlew test
fi fi
@ -32,5 +34,6 @@ while true; do
sleep 2 sleep 2
echo -e -n "\r\033[K waiting for changes ( ) ... " echo -e -n "\r\033[K waiting for changes ( ) ... "
sleep 2 sleep 2
echo -e -n "\r\033[K" echo -e -n "\r\033[K checking for changes"
done done