From 8f068ed016b7b6ea46b1ec2e0def38bbd3300813 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 19 Jan 2023 13:43:51 -0800 Subject: [PATCH] automatic history diff support --- sig | 22 ++++++++++++++++++---- test/test.bats | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/sig b/sig index a9ee962..0182240 100755 --- a/sig +++ b/sig @@ -479,11 +479,25 @@ cmd_verify() { esac done local -r head=$(git rev-parse --short HEAD) - if verify "$threshold" "$group" "$ref"; then - if [ ! -z "$diff" ] && [ ! -z "$ref" ] && [ "${ref}" != "${head}" ]; then - git --no-pager diff "${ref}" "${head}" + if [ ! -z "$diff" ] && [ -z "$ref" ]; then + echo "automode" + while read -r commit; do + echo "Checking commit: $commit" + if verify "$threshold" "$group" "$commit"; then + git --no-pager diff "${commit}" "${head}" + return 0 + fi + done <<< "$(git log --show-notes=signatures --pretty=format:"%H")" + else + echo "single" + if verify "$threshold" "$group" "$ref"; then + if [ ! -z "$diff" ] && [ ! -z "$ref" ]; then + local -r commit=$(git rev-parse --short "${ref}") + [ "${commit}" != "${head}" ] && \ + git --no-pager diff "${commit}" "${head}" + fi + return 0 fi - return 0 fi return 1 } diff --git a/test/test.bats b/test/test.bats index ccd8377..986431e 100644 --- a/test/test.bats +++ b/test/test.bats @@ -168,3 +168,36 @@ load test_helper [ "$status" -eq 0 ] echo "${output}" | grep "updated test string" } + +@test "Verify diff can automatically discover most recent valid commit" { + git init + + set_identity "user1" + echo "test string" > testfile + git add . + git commit -m "User 1 Commit 1" + + set_identity "user2" + sig add + + set_identity "user3" + sig add + + set_identity "user1" + echo "test string 2" > testfile + git add . + git commit -m "User 1 Commit 2" + + set_identity "user2" + sig add + + set_identity "user1" + git checkout -b feature_branch + echo "updated test string" > somefile1 + git add . + git commit -m "User 1 Commit 3" + + run sig verify --diff --threshold 3 + [ "$status" -eq 0 ] + echo "${output}" | grep "updated test string" +}