Skip to content

Commit c7cdaf4

Browse files
committed
Reduce code duplication in version check script
This extracts duplicated code to functions in check-version.sh. One effect is unfortunately that the specific commands being run are less explicitly clear when reading the script. However, small future changes, if accidentally made to one but not the other in either pair of "git status" commands, would create a much more confusing situation. So I think this change is justified overall.
1 parent 7110bf8 commit c7cdaf4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

check-version.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ trap 'echo "$0: Check failed. Stopping." >&2' ERR
1010
readonly version_path='VERSION'
1111
readonly changes_path='doc/source/changes.rst'
1212

13+
function check_status() {
14+
git status -s "$@"
15+
test -z "$(git status -s "$@")"
16+
}
17+
1318
function get_latest_tag() {
1419
local config_opts
1520
printf -v config_opts ' -c versionsort.suffix=-%s' alpha beta pre rc RC
@@ -23,13 +28,11 @@ test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable.
2328
echo "Checking that $version_path and $changes_path exist and have no uncommitted changes."
2429
test -f "$version_path"
2530
test -f "$changes_path"
26-
git status -s -- "$version_path" "$changes_path"
27-
test -z "$(git status -s -- "$version_path" "$changes_path")"
31+
check_status -- "$version_path" "$changes_path"
2832

2933
# This section can be commented out, if absolutely necessary.
3034
echo 'Checking that ALL changes are committed.'
31-
git status -s --ignore-submodules
32-
test -z "$(git status -s --ignore-submodules)"
35+
check_status --ignore-submodules
3336

3437
version_version="$(<"$version_path")"
3538
changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")"

0 commit comments

Comments
 (0)