Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
tests/libs/

#IntelliJ
/*.iml
/.idea/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ devbase-check/
│ ├── secrets.sh
│ ├── shell-fmt.sh
│ ├── shell.sh
│ ├── version-control.sh
│ ├── xml.sh
│ └── yaml.sh
├── scripts/
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ lint-base:
[group('lint')]
lint-all: lint-base

# Validate version control
[group('lint')]
lint-version-control:
@{{lint}}/version-control.sh

# Validate commit messages (conform)
[group('lint')]
lint-commits:
Expand Down
31 changes: 31 additions & 0 deletions linters/version-control.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
#
# SPDX-License-Identifier: MIT

set -uo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/../utils/colors.sh"

main() {
print_header "VERSION CONTROL"

if test -z "$(git status --porcelain | awk '{$1=$1};1')"; then
print_success "All changes are under version control"
return 0
else
print_error "Some changes are not under version control!

This can happen if

1. You forgot to version control your changes
2. A linter automatically fixed a problem or reformatted the code.

Please accept or discard any outstanding changes and try again."
return 1
fi
}

main
1 change: 1 addition & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ source "${SCRIPT_DIR}/../summary/common.sh"

# Base linters
LINTERS=(
"Version Control|git|just lint-version-control"
"Commits|conform|just lint-commits"
"Secrets|gitleaks|just lint-secrets"
"YAML|yamlfmt|just lint-yaml"
Expand Down
49 changes: 49 additions & 0 deletions tests/linters-version-control.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
#
# SPDX-License-Identifier: MIT

bats_require_minimum_version 1.13.0

load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
load "${BATS_TEST_DIRNAME}/test_helper.bash"

setup() {
common_setup
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
cd "$TEST_DIR"
init_git_repo
}

teardown() {
unstub conform 2>/dev/null || true
common_teardown
}

@test "version-control.sh accepts clean working directory" {
run --separate-stderr "$LINTERS_DIR/version-control.sh"

[ "x$BATS_TEST_COMPLETED" = "x" ] && echo "o:'${output}' e:'${stderr}'"
assert_success
assert_output --partial "All changes are under version control"
}

@test "version-control.sh rejects unversioned file" {
touch dummy-file
run "$LINTERS_DIR/version-control.sh"

[ "x$BATS_TEST_COMPLETED" = "x" ] && echo "o:'${output}' e:'${stderr}'"
assert_failure
assert_output --partial "Some changes are not under version control!

This can happen if

1. You forgot to version control your changes
2. A linter automatically fixed a problem or reformatted the code.

Please accept or discard any outstanding changes and try again."
}