Skip to content

Fix --uninstall/--upgrade crash when saved pre-commit-crypt hook is missing - #212

Merged
jmurty merged 1 commit into
elasticdog:mainfrom
substantial:fix/uninstall-missing-pre-commit-hook-backup
Jun 8, 2026
Merged

Fix --uninstall/--upgrade crash when saved pre-commit-crypt hook is missing#212
jmurty merged 1 commit into
elasticdog:mainfrom
substantial:fix/uninstall-missing-pre-commit-hook-backup

Conversation

@johnjensenish

@johnjensenish johnjensenish commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

transcrypt --uninstall (and --upgrade, which calls it) crashes when a pre-commit hook exists but transcrypt's saved pre-commit-crypt copy does not:

transcrypt: line 905: .husky/_/pre-commit-crypt: No such file or directory

The read on line 905 is unguarded, so set -euo pipefail aborts the script mid-uninstall.

Our use of husky for pre-commit hooks makes this state likely: core.hooksPath points at .husky/_, which husky re-generates on install — removing pre-commit-crypt — while installing its own pre-commit shim. But any missing saved copy triggers it.

The fix guards the read and falls through to the existing "Cannot safely disable Git pre-commit hook" warning — without the saved copy we can't tell whether the pre-commit hook is transcrypt's, so leave it alone and say so.

Includes a regression test (fails on main, passes with the fix). Full bats suite passes; shellcheck and shfmt clean.

uninstall_transcrypt() assumed that if a pre-commit hook exists, the
saved pre-commit-crypt copy also exists, and read it unconditionally.
When the saved copy is absent the input redirection fails and
'set -euo pipefail' aborts the whole script mid-uninstall.

This happens in repos where core.hooksPath points at a directory owned
by a hook manager such as husky: the manager re-generates its hooks
directory (removing pre-commit-crypt) and installs its own pre-commit
shim. It also breaks 'transcrypt --upgrade', which runs uninstall
internally.

Guard the read and fall through to the existing 'Cannot safely disable'
warning, since without the saved copy we cannot tell whether the
pre-commit hook is ours.
@johnjensenish
johnjensenish force-pushed the fix/uninstall-missing-pre-commit-hook-backup branch from 88af38e to 4f336db Compare June 5, 2026 00:41
@johnjensenish
johnjensenish marked this pull request as ready for review June 5, 2026 00:45
@jmurty

jmurty commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks very much for this well explained and tested fix

@jmurty
jmurty merged commit b76f597 into elasticdog:main Jun 8, 2026
7 checks passed
jmurty added a commit that referenced this pull request Jul 13, 2026
# By James Murty (4) and others
# Via James Murty (4) and GitHub (1)
* main:
  Add changelog entry for test suite improvements by @mattmc3
  Run tests in parallel with isolated per-test tmp locations for speed
  Mention in changelog support for symlinked gitattributes file for `--install` and `--upgrade` actions
  Fix symlink following for gitattributes files
  Set merge.conflictStyle in test helper
  Use read, rather than awk to address NUL byte handling issues
  Remove `hexdump` requirement from README, it is not required since version 2.2.3 (2023-03-09)
  Document fix for crash when pre-commit-crypt hook file is missing #212
  Fix --uninstall crash when saved pre-commit-crypt hook is missing

# Conflicts:
#	.github/workflows/run-bats-core-tests.yml
#	tests/_test_helper.bash
#	tests/v3/test_cleanup.bats
#	tests/v3/test_contexts.bats
#	tests/v3/test_crypt.bats
#	tests/v3/test_init.bats
#	tests/v3/test_not_inited.bats
#	tests/v3/test_pre_commit.bats
#	transcrypt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants