Skip to content

Commit 49b346a

Browse files
committed
handle --force when checking for incorrect password
1 parent a96733f commit 49b346a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ system, you must also run the `--upgrade` command in each repository:
3434

3535
## [Unreleased]
3636

37+
### Changed
38+
39+
- Improve check for incorrect password to avoid false report when transcrypt
40+
init is run with --force in a repo containing dirty files (#196)
41+
3742
### Fixed
3843

3944
- Fix pre-commit hook to use "fast" multi-threaded mode for Bash versions 5+ as

transcrypt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,13 @@ elif [[ $cipher ]]; then
15961596
validate_cipher
15971597
fi
15981598

1599+
list_dirty_files() {
1600+
{ git diff-index --name-status HEAD -- || git diff-index --stat HEAD -- || git diff-index HEAD -- || true; } 2>/dev/null
1601+
}
1602+
1603+
# shellcheck disable=SC2155
1604+
readonly GIT_DIRTY_FILES_BEFORE_INIT="$(list_dirty_files | grep $'\n' -c)"
1605+
15991606
# perform function calls to configure transcrypt
16001607
get_cipher
16011608
get_password
@@ -1620,12 +1627,10 @@ if [[ ! -f $GIT_ATTRIBUTES ]]; then
16201627
printf '#pattern filter=crypt diff=crypt merge=crypt\n' >"$GIT_ATTRIBUTES"
16211628
fi
16221629

1623-
# check for modified (dirty) files after transcrypt configuration which could
1630+
# check for newly modified (dirty) files after transcrypt configuration which could
16241631
# indicate an incorrect password
1625-
#
1626-
# check if the repo is dirty
1627-
if git status --porcelain 2>/dev/null | grep "^ M" >/dev/null; then
1628-
die 1 'Unexpected dirty files in the repository when configured by transcrypt%s, check your password.\n' "$CONTEXT_DESCRIPTION"
1632+
if [[ ${GIT_DIRTY_FILES_BEFORE_INIT} -lt $(list_dirty_files | grep $'\n' -c) ]]; then
1633+
die 1 'Unexpected new dirty files in the repository when configured by transcrypt%s, please check your password.\n' "$CONTEXT_DESCRIPTION"
16291634
fi
16301635

16311636
printf 'The repository has been successfully configured by transcrypt%s.\n' "$CONTEXT_DESCRIPTION"

0 commit comments

Comments
 (0)