automatic history diff support

This commit is contained in:
Lance Vick 2023-01-19 13:43:51 -08:00
parent f2fa9cf8fc
commit 8f068ed016
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
2 changed files with 51 additions and 4 deletions

22
sig
View File

@ -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
}

View File

@ -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"
}