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