Drew Davenport | 8a167fc | 2024-09-23 12:06:40 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # git pre-push hook to detect whether a developer is attempting to push |
| 4 | # non-public commits to a public repository. |
| 5 | |
| 6 | remote="$1" |
| 7 | url="$2" |
| 8 | |
| 9 | # Don't bother checking if this is being pushed to gerrit. |
| 10 | if [[ "$url" = "sso://googleplex-android/platform/external/drm_hwcomposer" ]] || |
| 11 | [[ "$url" = "sso://android.googlesource.com/platform/external/drm_hwcomposer" ]] |
| 12 | then |
| 13 | exit 0 |
| 14 | fi |
| 15 | |
| 16 | while read local_ref local_sha remote_ref remote_sha |
| 17 | do |
| 18 | # Gather a list of all commits that are to be pushed to the remote. |
| 19 | # remote_sha will be 000000 if there is no corresponding remote branch. |
| 20 | if [[ "$remote_sha" =~ "0000000000" ]]; then |
| 21 | commits=$(git rev-list $local_sha --not --remotes=$remote) |
| 22 | else |
| 23 | commits=$(git rev-list $remote_sha..$local_sha) |
| 24 | fi |
| 25 | |
| 26 | # Check each commit message for the prohibited prefix. |
| 27 | for commit in $commits; do |
| 28 | # Get the commit message. |
| 29 | message=$(git log -1 --pretty=%B $commit) |
| 30 | |
| 31 | # Check if the commit message starts with "ANDROID:" |
| 32 | if [[ "$message" == "ANDROID"* ]] || |
| 33 | [[ "$message" == "INTERNAL"* ]] || |
| 34 | [[ "$message" == "DO NOT MERGE"* ]]; then |
| 35 | echo "Error: Commit message starts with downstream tag:" |
| 36 | echo "$message" |
| 37 | echo "It looks like you're trying to push internal changes to an externally " |
| 38 | echo "visible repository: $url" |
| 39 | exit 1 |
| 40 | fi |
| 41 | done |
| 42 | done |
| 43 | |
| 44 | exit 0 |