Re: [PATCH v5 5/6] check-whitespace: detect if no base_commit is provided
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 18, 2024, 15:00 UTC
- Message-ID
- <xmqqfrs6ycc3.fsf@gitster.g>
- In-Reply-To
- <20240718081605.452366-6-karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 8 quoted lines
> + - |
> + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}}
> +
> + if test -z "$R"
> + then
> + echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!"
> + exit 1
> + fiThe same comment applies as the previous step.
R=${A-${B:?}} || exitshould be sufficient.
A demonstration.
$ unset A; unset B; C=${A-${B:?}} && echo "C=$C"
bash: B: parameter null or not set
$ A=a; unset B; C=${A-${B:?}} && echo "C=$C"
C=a
$ unset A; B=; C=${A-${B:?}} && echo "C=$C"
bash: B: parameter null or not set
$ unset A; B=b; C=${A-${B:?}} && echo "C=$C"
C=b
$ A=a; B=b; C=${A-${B:?}} && echo "C=$C"
C=aNote that the broken case we do not see C=<value> becaues the assignment fails with non-zero status.
Thanks.