Changeset View
Changeset View
Standalone View
Standalone View
contrib/source-control-tools/land-patch.sh
Show All 12 Lines | |||||
$0 [options] | $0 [options] | ||||
Land a commit on master after running any necessary scripts and sanity checks. | Land a commit on master after running any necessary scripts and sanity checks. | ||||
The patch is assumed to have been reviewed or generated from a trusted sourece. | The patch is assumed to have been reviewed or generated from a trusted sourece. | ||||
Options: | Options: | ||||
-d, --dry-run Dry run. Does everything but actually landing the change. | -d, --dry-run Dry run. Does everything but actually landing the change. | ||||
-h, --help Display this help message. | -h, --help Display this help message. | ||||
Environment Variables (for testing): | |||||
SANITY_CHECKS_COMMAND The command to override sanity checks (smoke tests). | |||||
GIT_COMMAND The command to override 'git' calls. | |||||
EOF | EOF | ||||
} | } | ||||
DRY_RUN=no | |||||
GIT_ARGS=() | GIT_ARGS=() | ||||
# Parse command line arguments | # Parse command line arguments | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
-d|--dry-run) | -d|--dry-run) | ||||
DRY_RUN=yes | |||||
GIT_ARGS+=("--dry-run") | GIT_ARGS+=("--dry-run") | ||||
shift # shift past argument | shift # shift past argument | ||||
;; | ;; | ||||
-h|--help) | -h|--help) | ||||
help_message | help_message | ||||
exit 0 | exit 0 | ||||
;; | ;; | ||||
*) | *) | ||||
echo "Error: Unrecognized argument: '$1'" | echo "Error: Unrecognized argument: '$1'" | ||||
help_message | help_message | ||||
exit 1 | exit 1 | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]]; then | if [[ ${DRY_RUN} == "no" ]] && [[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]]; then | ||||
echo "Error: This script assumes the commit to land is on master" | echo "Error: This script assumes the commit to land is on master" | ||||
exit 10 | exit 10 | ||||
fi | fi | ||||
TOPLEVEL=$(git rev-parse --show-toplevel) | TOPLEVEL=$(git rev-parse --show-toplevel) | ||||
# Sanity checks | # Sanity checks | ||||
"${TOPLEVEL}"/contrib/devtools/smoke-tests.sh | : "${SANITY_CHECKS_COMMAND:=${TOPLEVEL}/contrib/devtools/smoke-tests.sh}" | ||||
${SANITY_CHECKS_COMMAND} | |||||
# Push the change. Phabricator will automatically close the associated revision. | # Push the change. Phabricator will automatically close the associated revision. | ||||
git push "${GIT_ARGS[@]}" origin master | : "${GIT_COMMAND:=git}" | ||||
${GIT_COMMAND} push "${GIT_ARGS[@]}" origin master |