pre-push 879 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # .git/hooks/pre-push
  3. echo "Verifying if the target branch matches the version in gradle.properties"
  4. # Get the current branch name
  5. branch_name=$(git symbolic-ref --short HEAD)
  6. # Verify if branch name ends with '.x'
  7. if [[ ! "$branch_name" =~ \.x$ ]]; then
  8. echo "Branch name '$branch_name' does not end with '.x', skipping verification."
  9. exit 0
  10. fi
  11. # Extract version from gradle.properties
  12. version=$(cat gradle.properties | grep 'version=' | awk -F'=' '{print $2}')
  13. # Extract the version prefix from the version
  14. version_prefix=$(echo $version | cut -d'-' -f1 | sed 's/\.[0-9]*$//')
  15. # Check if branch starts with the version prefix
  16. if [[ "$branch_name" != "$version_prefix"* ]]; then
  17. echo "Branch name '$branch_name' does not match the version prefix '$version_prefix' in gradle.properties. Make sure you are pushing to the right branch."
  18. exit 1
  19. fi
  20. exit 0