|
|
@@ -508,19 +508,29 @@ function validate_commit |
|
|
|
{ |
|
|
|
# Remove prefix from names given in full |
|
|
|
HASH="$2" |
|
|
|
NAME="$(echo "$2" | sed -r "s/^$1://")" |
|
|
|
|
|
|
|
# find commit by its id, matching the type in $1 |
|
|
|
if git log --format="%s" --all | grep -E "^$1:$NAME$" --quiet;then |
|
|
|
HASH="$(git log --format="%h %s" --all | grep -E "\b$1:$NAME$" | cut -d ' ' -f 1)" |
|
|
|
NAME="$(git log --format=%s --max-count=1 "$HASH")" |
|
|
|
elif dbg git log "$HASH";then # find commit by its hash |
|
|
|
NAME="$(git log --format=%s --max-count=1 "$HASH")" |
|
|
|
# check that the commit matches the given type in $1 |
|
|
|
echo "$NAME" | grep -E "^$1:" --quiet || die "$HASH is not the commit hash of existing $1 of patient:$PATIENT" |
|
|
|
else |
|
|
|
die "$2 is neither the commit hash nor the name of existing $1 of patient:$PATIENT" |
|
|
|
fi |
|
|
|
FULLNAME="$2" |
|
|
|
NAME="$(echo "$2" | sed -E "s/^$1://")" |
|
|
|
local ncommits=$(git log --format=%s --all -E --grep "^$1:$NAME$" | grep -E "$FULLNAME$" -c) |
|
|
|
|
|
|
|
case "$ncommits" in |
|
|
|
"1") |
|
|
|
HASH=($(git log --format=%h --all -E --grep "^$1:$NAME$" --grep "$FULLNAME$" --all-match)) |
|
|
|
NAME="$(git log --format=%s --max-count=1 "$HASH")" |
|
|
|
;; |
|
|
|
"0") |
|
|
|
if git log "$HASH" &> /dev/null;then # find commit by its hash |
|
|
|
NAME="$(git log --format=%s --max-count=1 "$HASH")" |
|
|
|
# check that the commit matches the given type in $1 |
|
|
|
echo "$NAME" | grep -E "^$1:" --quiet || die "$HASH is not the commit hash of existing $1 of patient:$PATIENT" |
|
|
|
else |
|
|
|
die "$2 is neither the commit hash nor the name of existing $1 of patient:$PATIENT" |
|
|
|
fi |
|
|
|
;; |
|
|
|
*) |
|
|
|
die "$2 matches multiple commits of type $1 of patient:$PATIENT. |
|
|
|
Please be more specific" |
|
|
|
;; |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
# Validate hashes or resolve and expand names given after a list verb |
|
|
@@ -529,11 +539,11 @@ function validate_hashes |
|
|
|
local hash |
|
|
|
local out=() |
|
|
|
|
|
|
|
if [[ "${#HASHES[@]}" -gt 0 ]];then |
|
|
|
if [[ "${#HASHES[@]}" -gt 0 && "$HASHES" ]];then |
|
|
|
for hash in "${HASHES[@]}";do |
|
|
|
if git log --format="%s" --all | grep -E "$hash$" --quiet;then |
|
|
|
out+=($(git log --format="%h %s" --all | grep -E "$hash$" | cut -d ' ' -f 1)) |
|
|
|
elif dbg git log "$hash";then |
|
|
|
if git log --format=%s --all | grep -E "$hash$" --quiet;then |
|
|
|
out+=("$(git log --format=%h --all --grep "$hash$")") |
|
|
|
elif git log "$hash" &> /dev/null;then |
|
|
|
out+=("$(git log --format=%h --max-count=1 "$hash")") |
|
|
|
else |
|
|
|
die "$hash is neither the commit hash nor the name of an existing object of patient:$PATIENT" |
|
|
|