diff --git a/drill/record.sh b/drill/record.sh index 71bb2ae..26e0bd2 100644 --- a/drill/record.sh +++ b/drill/record.sh @@ -24,7 +24,7 @@ drill_resolve_ref_sha() { $2 == "refs/tags/" ref "^{}" { peeled=$1 } $2 == "refs/heads/" ref { head=$1 } $2 == "refs/tags/" ref { tag=$1 } - END { if (peeled) print peeled; else if (head) print head; else if (tag) print tag } + END { if (peeled) print peeled; else if (tag) print tag; else if (head) print head } ')" [ -n "$sha" ] || return 1 printf '%s\n' "$sha" diff --git a/test/cli.sh b/test/cli.sh index 8f1a2f9..65c2a65 100644 --- a/test/cli.sh +++ b/test/cli.sh @@ -3146,6 +3146,24 @@ check "drill record: default run ID joins version and UTC date" 0 "drill-0.9.1-2 # shellcheck disable=SC2016 check "drill record: an already exact ref stays exact" 0 "0123456789abcdef0123456789abcdef01234567" \ bash -c '. "$1/drill/record.sh"; drill_resolve_ref_sha repo 0123456789abcdef0123456789abcdef01234567' _ "$ROOT" + +REF_FIXTURE="$DRILL_RECORD_DIR/ref-fixture" +git init -q "$REF_FIXTURE" +git -C "$REF_FIXTURE" config user.name fixture +git -C "$REF_FIXTURE" config user.email fixture@example.invalid +printf 'branch\n' > "$REF_FIXTURE/value" +git -C "$REF_FIXTURE" add value +git -C "$REF_FIXTURE" commit -qm branch +git -C "$REF_FIXTURE" branch candidate +printf 'tag\n' > "$REF_FIXTURE/value" +git -C "$REF_FIXTURE" commit -qam tag +git -C "$REF_FIXTURE" tag candidate +TAG_SHA="$(git -C "$REF_FIXTURE" rev-parse 'refs/tags/candidate^{commit}')" +# The installer tries a tag before a branch when both share a name, so the +# record resolver must pin the same object rather than merely finding a ref. +# shellcheck disable=SC2016 +check "drill record: tag resolution matches the installer's tag-first channel" 0 "$TAG_SHA" \ + bash -c '. "$1/drill/record.sh"; drill_resolve_ref_sha "$2" candidate' _ "$ROOT" "$REF_FIXTURE" check "drill: help names --emit-record" 0 "--emit-record " bash "$ROOT/drill/drill.sh" --help check "drill: help names --run-id" 0 "--run-id " bash "$ROOT/drill/drill.sh" --help check "drill: --emit-record needs a value before any mutation" 2 "--emit-record needs a value" \