xref: /aosp_15_r20/external/drm_hwcomposer/hooks/check-non-public-commits (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
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
6remote="$1"
7url="$2"
8
9# Don't bother checking if this is being pushed to gerrit.
10if [[ "$url" = "sso://googleplex-android/platform/external/drm_hwcomposer" ]] ||
11   [[ "$url" = "sso://android.googlesource.com/platform/external/drm_hwcomposer" ]]
12then
13  exit 0
14fi
15
16while read local_ref local_sha remote_ref remote_sha
17do
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
42done
43
44exit 0
45