@@ -47,7 +47,7 @@ function assert_eq() {
47
47
}
48
48
49
49
function assert_substr() {
50
- if [[ " $1 " =~ " $2 " ]]; then
50
+ if [[ " $1 " == * " $2 " * ]]; then
51
51
return
52
52
fi
53
53
fail " '$1 ' does not contain '$2 '"
@@ -631,9 +631,9 @@ function git::rev_parse_branch() {
631
631
SHA2=" $( git rev-parse HEAD) "
632
632
633
633
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 "
635
635
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 "
637
637
}
638
638
639
639
# #############################################
@@ -675,13 +675,13 @@ function git::rev_parse_tag() {
675
675
git tag tag_4
676
676
677
677
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 "
679
679
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 "
681
681
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 "
683
683
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 "
685
685
}
686
686
687
687
# #############################################
@@ -724,10 +724,10 @@ function git::rev_parse_tag_annotated() {
724
724
725
725
# Annotated tags have their own SHA, which can be found with rev-parse, but
726
726
# 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 "
731
731
}
732
732
733
733
# #############################################
@@ -744,29 +744,29 @@ function git::rev_parse_sha() {
744
744
git add file_1
745
745
git commit -qam ' commit_1'
746
746
SHA1=" $( git rev-parse HEAD) "
747
- SHORT1=" $( echo " $ SHA1" | sed ' s/........$// ' ) "
747
+ SHORT1=" ${ SHA1% ????????} "
748
748
749
749
# Another commit on branch 1 (at HEAD)
750
750
date > file_2
751
751
git add file_2
752
752
git commit -qam ' commit_2'
753
753
SHA2=" $( git rev-parse HEAD) "
754
- SHORT2=" $( echo " $ SHA2" | sed ' s/........$// ' ) "
754
+ SHORT2=" ${ SHA2% ????????} "
755
755
756
756
# A commit on branch 2 (not at HEAD)
757
757
git checkout -b branch_2
758
758
date > file_3
759
759
git add file_3
760
760
git commit -qam ' commit_3'
761
761
SHA3=" $( git rev-parse HEAD) "
762
- SHORT3=" $( echo " $ SHA3" | sed ' s/........$// ' ) "
762
+ SHORT3=" ${ SHA3% ????????} "
763
763
764
764
# Another commit on branch 2 (at HEAD)
765
765
date > file_4
766
766
git add file_4
767
767
git commit -qam ' commit_4'
768
768
SHA4=" $( git rev-parse HEAD) "
769
- SHORT4=" $( echo " $ SHA4" | sed ' s/........$// ' ) "
769
+ SHORT4=" ${ SHA4% ????????} "
770
770
771
771
assert_eq " $( git rev-parse " $SHA1 " ) " " $SHA1 "
772
772
assert_eq " $( git rev-parse " $SHA1 ^{commit}" ) " " $SHA1 "
@@ -804,10 +804,10 @@ function git::rev_parse_non_existent_sha() {
804
804
# As long as it tastes like a SHA, rev-parse is happy, but there is no
805
805
# commit for it.
806
806
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"
808
808
# Less-than-full SHAs do not work.
809
809
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"
811
811
}
812
812
813
813
#
@@ -820,15 +820,15 @@ function list_tests() {
820
820
declare -F \
821
821
| cut -f3 -d' ' \
822
822
| grep " ^git::" \
823
- | while read X; do declare -F $X ; done \
823
+ | while read -r X; do declare -F " $X " ; done \
824
824
| sort -n -k2 \
825
825
| cut -f1 -d' ' \
826
826
| sed ' s/^git:://'
827
827
)
828
828
}
829
829
830
830
# Figure out which, if any, tests to run.
831
- all_tests=( $( list_tests) )
831
+ mapfile -t all_tests < <( list_tests)
832
832
tests_to_run=()
833
833
834
834
function print_tests() {
@@ -855,7 +855,7 @@ for arg; do
855
855
if [[ " ${t} " =~ ${arg} ]]; then
856
856
nmatches=$(( nmatches+ 1 ))
857
857
# Don't run tests twice, just keep the first match.
858
- if [[ " ${tests_to_run[*]} " =~ " ${t} " ]]; then
858
+ if [[ " ${tests_to_run[*]} " == * " ${t} " * ]]; then
859
859
continue
860
860
fi
861
861
tests_to_run+=(" ${t} " )
@@ -908,7 +908,8 @@ function run_test() {
908
908
shift
909
909
910
910
declare -g " $retvar "
911
- local restore_opts=$( set +o)
911
+ local restore_opts
912
+ restore_opts=$( set +o)
912
913
set +o errexit
913
914
set +o nounset
914
915
set +o pipefail
0 commit comments