diff --git a/push.sh b/push.sh index 17f85e6..733bff1 100755 --- a/push.sh +++ b/push.sh @@ -1,36 +1,36 @@ #!/usr/bin/env bash -# Define the branch name -BRANCH_NAME=dev +set -euo pipefail -# Check if the branch exists locally -if git rev-parse --verify $BRANCH_NAME > /dev/null 2>&1; then +DEV_BRANCH="dev" +MAIN_BRANCH="main" - # Get commit message - # message=$(git diff | ~/scripts/shelly 'write a short git commit message for this diff') - message="$(date --iso-8601=seconds)" - echo $message - - # Add and commit changes - git add . - git commit -m "$message" - - # Pull the latest changes from the main branch to ensure we're up to date - git pull origin main - - # Push the changes to the remote branch named dev_$(hostname) - git push origin $BRANCH_NAME - - # Merge to main - git switch main - git merge dev - git commit - git push - - # Switch to the branch - git switch $BRANCH_NAME - -else - echo "Branch $BRANCH_NAME does not exist locally!" +if ! git rev-parse --verify "$DEV_BRANCH" > /dev/null 2>&1; then + echo "Branch $DEV_BRANCH does not exist locally!" exit 1 fi + +git switch "$DEV_BRANCH" + +message="$(date --iso-8601=seconds)" +echo "$message" + +git add -A +if ! git diff --cached --quiet; then + git commit -m "$message" +else + echo "No changes to commit on $DEV_BRANCH." +fi + +git fetch origin "$MAIN_BRANCH" +git merge --no-edit "origin/$MAIN_BRANCH" + +git push origin "$DEV_BRANCH" + +git switch "$MAIN_BRANCH" +git fetch origin "$MAIN_BRANCH" +git merge --no-edit "origin/$MAIN_BRANCH" +git merge --no-edit "$DEV_BRANCH" +git push origin "$MAIN_BRANCH" + +git switch "$DEV_BRANCH"