@@ -47,7 +47,7 @@ function assert_eq() {
4747}
4848
4949function assert_substr() {
50- if [[ " $1 " =~ " $2 " ]]; then
50+ if [[ " $1 " == * " $2 " * ]]; then
5151 return
5252 fi
5353 fail " '$1 ' does not contain '$2 '"
@@ -631,9 +631,9 @@ function git::rev_parse_branch() {
631631 SHA2=" $( git rev-parse HEAD) "
632632
633633 assert_eq " $( git rev-parse branch_1) " " $SHA1 "
634- assert_eq " $( git rev-parse branch_1^{commit}) " " $SHA1 "
634+ assert_eq " $( git rev-parse ' branch_1^{commit}' ) " " $SHA1 "
635635 assert_eq " $( git rev-parse branch_2) " " $SHA2 "
636- assert_eq " $( git rev-parse branch_2^{commit}) " " $SHA2 "
636+ assert_eq " $( git rev-parse ' branch_2^{commit}' ) " " $SHA2 "
637637}
638638
639639# #############################################
@@ -675,13 +675,13 @@ function git::rev_parse_tag() {
675675 git tag tag_4
676676
677677 assert_eq " $( git rev-parse tag_1) " " $SHA1 "
678- assert_eq " $( git rev-parse tag_1^{commit}) " " $SHA1 "
678+ assert_eq " $( git rev-parse ' tag_1^{commit}' ) " " $SHA1 "
679679 assert_eq " $( git rev-parse tag_2) " " $SHA2 "
680- assert_eq " $( git rev-parse tag_2^{commit}) " " $SHA2 "
680+ assert_eq " $( git rev-parse ' tag_2^{commit}' ) " " $SHA2 "
681681 assert_eq " $( git rev-parse tag_3) " " $SHA3 "
682- assert_eq " $( git rev-parse tag_3^{commit}) " " $SHA3 "
682+ assert_eq " $( git rev-parse ' tag_3^{commit}' ) " " $SHA3 "
683683 assert_eq " $( git rev-parse tag_4) " " $SHA4 "
684- assert_eq " $( git rev-parse tag_4^{commit}) " " $SHA4 "
684+ assert_eq " $( git rev-parse ' tag_4^{commit}' ) " " $SHA4 "
685685}
686686
687687# #############################################
@@ -724,10 +724,10 @@ function git::rev_parse_tag_annotated() {
724724
725725 # Annotated tags have their own SHA, which can be found with rev-parse, but
726726 # it doesn't make sense to test rev-parse against itself.
727- assert_eq " $( git rev-parse anntag_1^{commit}) " " $SHA1 "
728- assert_eq " $( git rev-parse anntag_2^{commit}) " " $SHA2 "
729- assert_eq " $( git rev-parse anntag_3^{commit}) " " $SHA3 "
730- assert_eq " $( git rev-parse anntag_4^{commit}) " " $SHA4 "
727+ assert_eq " $( git rev-parse ' anntag_1^{commit}' ) " " $SHA1 "
728+ assert_eq " $( git rev-parse ' anntag_2^{commit}' ) " " $SHA2 "
729+ assert_eq " $( git rev-parse ' anntag_3^{commit}' ) " " $SHA3 "
730+ assert_eq " $( git rev-parse ' anntag_4^{commit}' ) " " $SHA4 "
731731}
732732
733733# #############################################
@@ -744,29 +744,29 @@ function git::rev_parse_sha() {
744744 git add file_1
745745 git commit -qam ' commit_1'
746746 SHA1=" $( git rev-parse HEAD) "
747- SHORT1=" $( echo " $ SHA1" | sed ' s/........$// ' ) "
747+ SHORT1=" ${ SHA1% ????????} "
748748
749749 # Another commit on branch 1 (at HEAD)
750750 date > file_2
751751 git add file_2
752752 git commit -qam ' commit_2'
753753 SHA2=" $( git rev-parse HEAD) "
754- SHORT2=" $( echo " $ SHA2" | sed ' s/........$// ' ) "
754+ SHORT2=" ${ SHA2% ????????} "
755755
756756 # A commit on branch 2 (not at HEAD)
757757 git checkout -b branch_2
758758 date > file_3
759759 git add file_3
760760 git commit -qam ' commit_3'
761761 SHA3=" $( git rev-parse HEAD) "
762- SHORT3=" $( echo " $ SHA3" | sed ' s/........$// ' ) "
762+ SHORT3=" ${ SHA3% ????????} "
763763
764764 # Another commit on branch 2 (at HEAD)
765765 date > file_4
766766 git add file_4
767767 git commit -qam ' commit_4'
768768 SHA4=" $( git rev-parse HEAD) "
769- SHORT4=" $( echo " $ SHA4" | sed ' s/........$// ' ) "
769+ SHORT4=" ${ SHA4% ????????} "
770770
771771 assert_eq " $( git rev-parse " $SHA1 " ) " " $SHA1 "
772772 assert_eq " $( git rev-parse " $SHA1 ^{commit}" ) " " $SHA1 "
@@ -804,10 +804,10 @@ function git::rev_parse_non_existent_sha() {
804804 # As long as it tastes like a SHA, rev-parse is happy, but there is no
805805 # commit for it.
806806 assert_eq " $( git rev-parse 0123456789abcdef0123456789abcdef01234567) " " 0123456789abcdef0123456789abcdef01234567"
807- assert_substr " $( git rev-parse 0123456789abcdef0123456789abcdef01234567^{commit} 2>&1 || true) " " unknown revision"
807+ assert_substr " $( git rev-parse ' 0123456789abcdef0123456789abcdef01234567^{commit}' 2>&1 || true) " " unknown revision"
808808 # Less-than-full SHAs do not work.
809809 assert_substr " $( git rev-parse 0123456789abcdef 2>&1 || true) " " unknown revision"
810- assert_substr " $( git rev-parse 0123456789abcdef^{commit} 2>&1 || true) " " unknown revision"
810+ assert_substr " $( git rev-parse ' 0123456789abcdef^{commit}' 2>&1 || true) " " unknown revision"
811811}
812812
813813#
@@ -820,15 +820,15 @@ function list_tests() {
820820 declare -F \
821821 | cut -f3 -d' ' \
822822 | grep " ^git::" \
823- | while read X; do declare -F $X ; done \
823+ | while read -r X; do declare -F " $X " ; done \
824824 | sort -n -k2 \
825825 | cut -f1 -d' ' \
826826 | sed ' s/^git:://'
827827 )
828828}
829829
830830# Figure out which, if any, tests to run.
831- all_tests=( $( list_tests) )
831+ mapfile -t all_tests < <( list_tests)
832832tests_to_run=()
833833
834834function print_tests() {
@@ -855,7 +855,7 @@ for arg; do
855855 if [[ " ${t} " =~ ${arg} ]]; then
856856 nmatches=$(( nmatches+ 1 ))
857857 # Don't run tests twice, just keep the first match.
858- if [[ " ${tests_to_run[*]} " =~ " ${t} " ]]; then
858+ if [[ " ${tests_to_run[*]} " == * " ${t} " * ]]; then
859859 continue
860860 fi
861861 tests_to_run+=(" ${t} " )
@@ -908,7 +908,8 @@ function run_test() {
908908 shift
909909
910910 declare -g " $retvar "
911- local restore_opts=$( set +o)
911+ local restore_opts
912+ restore_opts=$( set +o)
912913 set +o errexit
913914 set +o nounset
914915 set +o pipefail
0 commit comments