Skip to content

Commit 7765818

Browse files
authored
Merge branch 'master' into introduce_ruff
2 parents 948a36d + 23928fb commit 7765818

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [1.98.0](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.97.4...v1.98.0) (2025-03-25)
6+
7+
8+
### Features
9+
10+
* **docker:** Support execution on repos under `git worktree` ([#845](https://github.com/antonbabenko/pre-commit-terraform/issues/845)) ([e64974e](https://github.com/antonbabenko/pre-commit-terraform/commit/e64974ed7745a3c35882b71be49fc89570cb006e))
11+
512
## [1.97.4](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.97.3...v1.97.4) (2025-02-26)
613

714

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
1818
'replace the entire README.md file each time.'
1919
)
2020
subcommand_parser.add_argument(
21-
'--dest', dest='dest', default='README.md',
21+
'--dest',
22+
dest='dest',
23+
default='README.md',
2224
)
2325
subcommand_parser.add_argument(
24-
'--sort-inputs-by-required', dest='sort', action='store_true',
26+
'--sort-inputs-by-required',
27+
dest='sort',
28+
action='store_true',
2529
help='[deprecated] use --sort-by-required instead',
2630
)
2731
subcommand_parser.add_argument(
28-
'--sort-by-required', dest='sort', action='store_true',
32+
'--sort-by-required',
33+
dest='sort',
34+
action='store_true',
2935
)
3036
subcommand_parser.add_argument(
3137
'--with-aggregate-type-defaults',
@@ -51,8 +57,9 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
5157

5258
dirs: list[str] = []
5359
for filename in cast_to(list[str], parsed_cli_args.filenames):
54-
if (os.path.realpath(filename) not in dirs and
55-
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
60+
if os.path.realpath(filename) not in dirs and (
61+
filename.endswith('.tf') or filename.endswith('.tfvars')
62+
):
5663
dirs.append(os.path.dirname(filename))
5764

5865
retval = ReturnCode.OK
@@ -64,13 +71,14 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6471
if cast_to(bool, parsed_cli_args.sort):
6572
procArgs.append('--sort-by-required')
6673
procArgs.append('md')
67-
procArgs.append("./{dir}".format(dir=dir))
74+
procArgs.append('./{dir}'.format(dir=dir))
6875
procArgs.append('>')
6976
procArgs.append(
70-
'./{dir}/{dest}'.
71-
format(dir=dir, dest=cast_to(bool, parsed_cli_args.dest)),
77+
'./{dir}/{dest}'.format(
78+
dir=dir, dest=cast_to(bool, parsed_cli_args.dest)
79+
),
7280
)
73-
subprocess.check_call(" ".join(procArgs), shell=True)
81+
subprocess.check_call(' '.join(procArgs), shell=True)
7482
except subprocess.CalledProcessError as e:
7583
print(e)
7684
retval = ReturnCode.ERROR

tests/pytest/terraform_docs_replace_test.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def test_arg_parser_populated() -> None:
2424
def test_check_is_deprecated() -> None:
2525
"""Verify that `replace-docs` shows a deprecation warning."""
2626
deprecation_msg_regex = (
27-
r'^`terraform_docs_replace` hook is DEPRECATED\.'
28-
'For migration.*$'
27+
r'^`terraform_docs_replace` hook is DEPRECATED\.For migration.*$'
2928
)
3029
with pytest.warns(UserWarning, match=deprecation_msg_regex):
3130
# not `pytest.deprecated_call()` due to this being a user warning
@@ -70,10 +69,10 @@ def test_check_is_deprecated() -> None:
7069
'pre_commit_terraform.terraform_docs_replace',
7170
)
7271
def test_control_flow_positive(
73-
expected_cmds: list[str],
74-
mocker: pytest_mock.MockerFixture,
75-
monkeypatch: pytest.MonkeyPatch,
76-
parsed_cli_args: Namespace,
72+
expected_cmds: list[str],
73+
mocker: pytest_mock.MockerFixture,
74+
monkeypatch: pytest.MonkeyPatch,
75+
parsed_cli_args: Namespace,
7776
) -> None:
7877
"""Check that the subcommand's happy path works."""
7978
check_call_mock = mocker.Mock()
@@ -86,7 +85,7 @@ def test_control_flow_positive(
8685
assert ReturnCode.OK == invoke_cli_app(parsed_cli_args)
8786

8887
executed_commands = [
89-
cmd for ((cmd, ), _shell) in check_call_mock.call_args_list
88+
cmd for ((cmd,), _shell) in check_call_mock.call_args_list
9089
]
9190

9291
assert len(expected_cmds) == check_call_mock.call_count
@@ -98,8 +97,8 @@ def test_control_flow_positive(
9897
'pre_commit_terraform.terraform_docs_replace',
9998
)
10099
def test_control_flow_negative(
101-
mocker: pytest_mock.MockerFixture,
102-
monkeypatch: pytest.MonkeyPatch,
100+
mocker: pytest_mock.MockerFixture,
101+
monkeypatch: pytest.MonkeyPatch,
103102
) -> None:
104103
"""Check that the subcommand's error processing works."""
105104
parsed_cli_args = Namespace(

tools/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ wdir="$(pwd)"
3939
if ! su-exec "$USERID" "$BASHPATH" -c "test -w $wdir && test -r $wdir"; then
4040
echo_error_and_exit "uid:gid $USERID lacks permissions to $wdir/"
4141
fi
42-
wdirgitindex="$wdir/.git/index"
42+
wdirgitindex="$(git rev-parse --git-dir 2>&1)/index" || echo_error_and_exit "${wdirgitindex%/index}"
4343
if ! su-exec "$USERID" "$BASHPATH" -c "test -w $wdirgitindex && test -r $wdirgitindex"; then
4444
echo_error_and_exit "uid:gid $USERID cannot write to $wdirgitindex"
4545
fi

0 commit comments

Comments
 (0)