From 0a9c731969fe590f82a5a4e34f9f1470d57d20b2 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 23 Aug 2018 22:01:53 -0600 Subject: [PATCH 1/2] Upload hook that guides people towards AOSP. The canonical location of certain parts of the source tree live in AOSP, and should not be changed internally to avoid merge conflicts. This initially starts with "OWNERS" files, but the hook can easily be repeated to match any files based on file path regexes. Bug: 113136846 Test: manual Change-Id: I113e63b6133f20389d84ec0d6d8b81cdbdf35d38 Merged-In: I113e63b6133f20389d84ec0d6d8b81cdbdf35d38 --- PREUPLOAD.cfg | 2 ++ tools/aosp/aosp_sha.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 tools/aosp/aosp_sha.sh diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index 1f8ab21783ac9..07b0ae10fd551 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -14,3 +14,5 @@ api_lint_hook = ${REPO_ROOT}/frameworks/base/tools/apilint/apilint_sha.sh ${PREU strings_lint_hook = ${REPO_ROOT}/frameworks/base/tools/stringslint/stringslint_sha.sh ${PREUPLOAD_COMMIT} hidden_api_txt_hook = ${REPO_ROOT}/frameworks/base/tools/hiddenapi/checksorted_sha.sh ${PREUPLOAD_COMMIT} ${REPO_ROOT} + +owners_hook = ${REPO_ROOT}/frameworks/base/tools/aosp/aosp_sha.sh ${PREUPLOAD_COMMIT} "OWNERS$" diff --git a/tools/aosp/aosp_sha.sh b/tools/aosp/aosp_sha.sh new file mode 100755 index 0000000000000..29bf74c7a8b98 --- /dev/null +++ b/tools/aosp/aosp_sha.sh @@ -0,0 +1,18 @@ +#!/bin/bash +LOCAL_DIR="$( dirname ${BASH_SOURCE} )" + +if git branch -vv | grep "^*" | grep "\[aosp/master" > /dev/null; then + # Change appears to be in AOSP + exit 0 +else + # Change appears to be non-AOSP; search for files + git show --name-only --pretty=format: $1 | grep $2 | while read file; do + echo + echo -e "\033[0;31mThe source of truth for '$file' is in AOSP.\033[0m" + echo + echo "If your change contains no confidential details, please upload and merge" + echo "this change at https://android-review.googlesource.com/." + echo + exit 77 + done +fi From 5b471996ebebce503487ca08c86ee7eb62e6dd3d Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 11 Sep 2018 10:36:57 -0600 Subject: [PATCH 2/2] Tweaks to AOSP upload hook logic. Lists all matching files, and slightly more robust path handling. Bug: 113136846 Test: manual Change-Id: Ic1971a3df97b8b137993b5856b47d0d706a996cd --- tools/aosp/aosp_sha.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/aosp/aosp_sha.sh b/tools/aosp/aosp_sha.sh index 29bf74c7a8b98..e50c70d0656a4 100755 --- a/tools/aosp/aosp_sha.sh +++ b/tools/aosp/aosp_sha.sh @@ -1,18 +1,24 @@ #!/bin/bash -LOCAL_DIR="$( dirname ${BASH_SOURCE} )" +LOCAL_DIR="$( dirname "${BASH_SOURCE}" )" -if git branch -vv | grep "^*" | grep "\[aosp/master" > /dev/null; then +if git branch -vv | grep -q -P "^\*[^\[]+\[aosp/"; then # Change appears to be in AOSP exit 0 else # Change appears to be non-AOSP; search for files - git show --name-only --pretty=format: $1 | grep $2 | while read file; do - echo + count=0 + while read -r file ; do + if (( count == 0 )); then + echo + fi echo -e "\033[0;31mThe source of truth for '$file' is in AOSP.\033[0m" + (( count++ )) + done < <(git show --name-only --pretty=format: $1 | grep -- "$2") + if (( count != 0 )); then echo - echo "If your change contains no confidential details, please upload and merge" - echo "this change at https://android-review.googlesource.com/." + echo "If your change contains no confidential details (such as security fixes), please" + echo "upload and merge this change at https://android-review.googlesource.com/." echo exit 77 - done + fi fi