diff options
-rw-r--r-- | local/tests/lib.sh | 54 | ||||
-rwxr-xr-x | local/tests/update-06-copyright.sh | 36 | ||||
-rwxr-xr-x | local/update-06-copyright | 15 |
3 files changed, 104 insertions, 1 deletions
diff --git a/local/tests/lib.sh b/local/tests/lib.sh index 12160a7..cd6543d 100644 --- a/local/tests/lib.sh +++ b/local/tests/lib.sh @@ -50,6 +50,18 @@ run_test() { ) } +# Run the test for specified branch, presuming it's a new branch. +# $1 - branch name +run_test_branch() { + local branch=${1} + + ( + set -- "refs/heads/${branch}" 0000000000000000000000000000000000000000 HEAD + set +e + . "${HOOK_PATH}" + ) +} + # Run the hook for all commits since the initial commit. # Expect success. test_success() { @@ -58,6 +70,16 @@ test_success() { : $(( TEST_RET |= ${?} )) } +# Run the hook presuming new branch is added. +# Expect success. +# $1 - branch name +test_branch_success() { + local branch=${1} + run_test_branch "${branch}" + tend ${?} + : $(( TEST_RET |= ${?} )) +} + # Run the hook for all commits since the initial commit. # Expect failure with message matching the pattern. # $1 - bash pattern to match @@ -74,3 +96,35 @@ test_failure() { tend ${?} "'${msg}' != '${expected}'" : $(( TEST_RET |= ${?} )) } + +# Run the hook presuming new branch is added. +# Expect failure with message matching the pattern. +# $1 - branch name +# $2 - bash pattern to match +test_branch_failure() { + local branch=${1} + local expected=${2} + local msg + + if msg=$(run_test_branch "${branch}"); then + tend 1 "Hook unexpectedly succeeded" + return 1 + fi + + [[ ${msg} == ${expected} ]] + tend ${?} "'${msg}' != '${expected}'" + : $(( TEST_RET |= ${?} )) +} + +# Run the hook presuming branch is being removed. +# Expect success (our hooks shouldn't prevent removal). +test_branch_removal() { + ( + set -- "refs/heads/removed-branch" HEAD 0000000000000000000000000000000000000000 + set +e + . "${HOOK_PATH}" + ) + + tend ${?} + : $(( TEST_RET |= ${?} )) +} diff --git a/local/tests/update-06-copyright.sh b/local/tests/update-06-copyright.sh index 0e0d3be..0b93044 100755 --- a/local/tests/update-06-copyright.sh +++ b/local/tests/update-06-copyright.sh @@ -343,4 +343,40 @@ test_failure "${FAIL_NO_SIGNOFF}" eoutdent +einfo "Branch addition / removal tests" +eindent + +tbegin "Forked branch with sign-off present" +git checkout -q -b test-branch +git commit --allow-empty -m "Commit with sign-off + +Signed-off-by: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>" -q +test_branch_success test-branch + +tbegin "Forked branch with new non-signed commit" +git checkout -q -b test-branch +git commit --allow-empty -m "Commit without sign-off" -q +test_branch_failure test-branch "${FAIL_NO_SIGNOFF}" + +tbegin "Copy of master branch" +git checkout -q -b test-branch +test_branch_success test-branch + +tbegin "New independent branch with sign-off" +git checkout --orphan test-branch -q +git commit --allow-empty -m "Commit with sign-off + +Signed-off-by: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>" -q +test_branch_success test-branch + +tbegin "New independent branch without sign-off" +git checkout --orphan test-branch -q +git commit --allow-empty -m "Commit without sign-off" -q +test_branch_failure test-branch "${FAIL_NO_SIGNOFF}" + +tbegin "Branch removal" +test_branch_removal + +eoutdent + exit "${TEST_RET}" diff --git a/local/update-06-copyright b/local/update-06-copyright index 90b6a66..ec308e0 100755 --- a/local/update-06-copyright +++ b/local/update-06-copyright @@ -66,6 +66,19 @@ fi ret=0 +# special cases +zeros=0000000000000000000000000000000000000000 +# branch removal +[[ ${newrev} == "${zeros}" ]] && exit 0 +# new branch; try to find a merge base with master +if [[ ${oldrev} == "${zeros}" && ${refname} != refs/heads/master ]]; then + mergebase=$(git merge-base refs/heads/master "${newrev}") + [[ -n ${mergebase} ]] && oldrev=${mergebase} +fi +rev_list_arg="${oldrev}..${newrev}" +# new and no common commit? gotta check them all +[[ ${oldrev} == "${zeros}" ]] && rev_list_arg="${newrev}" + while read -r commithash; do # verify that the commit message contains Signed-off-by signoff=no @@ -150,7 +163,7 @@ while read -r commithash; do echo " last found: ${realname}" ret=1;; esac -done < <(git rev-list "${oldrev}..${newrev}") +done < <(git rev-list "${rev_list_arg}") # --- Finished exit "${ret}" |