Changeset View
Changeset View
Standalone View
Standalone View
contrib/source-control-tools/land-patch.sh
Show All 20 Lines | |||||
Environment Variables (for testing): | Environment Variables (for testing): | ||||
SANITY_CHECKS_COMMAND The command to override sanity checks (smoke tests). | SANITY_CHECKS_COMMAND The command to override sanity checks (smoke tests). | ||||
GIT_COMMAND The command to override 'git' calls. | GIT_COMMAND The command to override 'git' calls. | ||||
EOF | EOF | ||||
} | } | ||||
DRY_RUN=no | DRY_RUN=no | ||||
GIT_ARGS=() | GIT_ARGS=("--porcelain") | ||||
# 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 | DRY_RUN=yes | ||||
GIT_ARGS+=("--dry-run") | GIT_ARGS+=("--dry-run") | ||||
shift # shift past argument | shift # shift past argument | ||||
Show All 16 Lines | |||||
fi | fi | ||||
TOPLEVEL=$(git rev-parse --show-toplevel) | TOPLEVEL=$(git rev-parse --show-toplevel) | ||||
# Sanity checks | # Sanity checks | ||||
: "${SANITY_CHECKS_COMMAND:=${TOPLEVEL}/contrib/devtools/smoke-tests.sh}" | : "${SANITY_CHECKS_COMMAND:=${TOPLEVEL}/contrib/devtools/smoke-tests.sh}" | ||||
${SANITY_CHECKS_COMMAND} | ${SANITY_CHECKS_COMMAND} | ||||
# Push the change. Phabricator will automatically close the associated revision. | |||||
: "${GIT_COMMAND:=git}" | : "${GIT_COMMAND:=git}" | ||||
${GIT_COMMAND} push "${GIT_ARGS[@]}" origin master | while true; do | ||||
# Make sure master is up-to-date. If there is a merge conflict, this script | |||||
# will not attempt to resolve it and simply fail. | |||||
${GIT_COMMAND} pull --rebase origin master | |||||
# Push the change. Phabricator will automatically close the associated revision. | |||||
set +e | |||||
PUSH_OUTPUT=$(${GIT_COMMAND} push "${GIT_ARGS[@]}" origin master) | |||||
PUSH_EXIT_CODE=$? | |||||
set -e | |||||
if (( PUSH_EXIT_CODE == 0 )); then | |||||
exit 0 | |||||
else | |||||
echo "${PUSH_OUTPUT}" | grep "\! refs/heads/master:refs/heads/master \[rejected\] (non-fast-forward) Done" | |||||
fi | |||||
done |