Skip to content

Commit

Permalink
HIVE-20191: PreCommit patch application doesn't fail if patch is empt…
Browse files Browse the repository at this point in the history
…y (Daniel Voros via Zoltan Haindrich, Vihang Karajgaonkar)

Signed-off-by: Zoltan Haindrich <kirk@rxd.hu>
  • Loading branch information
dvoros authored and kgyrtkirk committed Aug 27, 2018
1 parent 826e553 commit 14b972e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
35 changes: 30 additions & 5 deletions dev-support/jenkins-common.sh
Expand Up @@ -31,12 +31,9 @@ get_branch_name() {
local branch="$2" # $2 is a default branch

if [[ -n $PATCH_NAME ]]; then
# Test PATCH_NAME:
# HIVE-123.patch HIVE-123.1.patch HIVE-123-tez.patch HIVE-123.1-tez.patch
# HIVE-XXXX.patch, HIVE-XXXX.XX.patch HIVE-XXXX.XX-branch.patch HIVE-XXXX-branch.patch
if [[ $PATCH_NAME =~ ^HIVE-[0-9]+(\.[0-9]+)?(-[A-Za-z0-9.-]+)?\.(patch|patch.\txt)$ ]]; then
if [[ $PATCH_NAME =~ ^HIVE-[0-9]+(\.[0-9]+)?([-\.][A-Za-z0-9.-]+)?\.(patch|patch.\txt)$ ]]; then
if [[ -n "${BASH_REMATCH[2]}" ]]; then
branch=${BASH_REMATCH[2]#*-}
branch=${BASH_REMATCH[2]:1}
fi
elif [[ $PATCH_NAME =~ ^(HIVE-[0-9]+\.)?D[0-9]+(\.[0-9]+)?\.(patch|patch.\txt)$ ]]; then
# It will assume the default branch
Expand All @@ -51,6 +48,34 @@ get_branch_name() {
return 0
}

# Used during development for testing get_branch_name
_test_get_branch_name() {
do_test() {
local PATCH_NAME="$1"
local EXPECTED="$2"

local ACTUAL=$(get_branch_name $PATCH_NAME master)

[[ "$ACTUAL" == "$EXPECTED" ]] || echoerr "$PATCH_NAME failed ($ACTUAL != $EXPECTED)"
}

# Branch not spcified in patch name
do_test "HIVE-123.patch" "master"
do_test "HIVE-123.1.patch" "master"

# Branch name separated by '-'
do_test "HIVE-123-tez.patch" "tez"
do_test "HIVE-123.1-tez.patch" "tez"
do_test "HIVE-123-branch-2.patch" "branch-2"
do_test "HIVE-123.1-branch-2.patch" "branch-2"

# Branch name separated by '.'
do_test "HIVE-123.tez.patch" "tez"
do_test "HIVE-123.1.tez.patch" "tez"
do_test "HIVE-123.branch-2.patch" "branch-2"
do_test "HIVE-123.1.branch-2.patch" "branch-2"
}

# Gets the attachment identifier of a JIRA attachment file
get_attachment_id() {
local jira_attachment_url="$1"
Expand Down
9 changes: 8 additions & 1 deletion testutils/ptest2/src/main/resources/smart-apply-patch.sh
Expand Up @@ -90,5 +90,12 @@ fi

echo Going to apply patch with: git apply -p$PLEVEL
git apply -p$PLEVEL -3 $PATCH_FILE
ret=$?

cleanup $?
# Fail if patch was empty
if [[ -z $(git status --porcelain) ]]; then
echo "The patch had no effect. Was this change committed in another patch? Are you using the correct branch?"
cleanup 1
fi

cleanup $ret

0 comments on commit 14b972e

Please sign in to comment.