Restoring unstaged changes fails with git < 2.35.0
scop opened this issue ยท 4 comments
๐ง Summary
Committing something with unstaged changes ends up with:
Couldn't restore hidden unstaged files: exit status 129
...and the unstaged changes are left in a patch in .git/info.
This is with git 2.34.1, up to date Ubuntu 22.
Per verbose logs, this because of use of --allow-empty
(added in #543).
The --allow-empty
option was added in git 2.35.0: https://github.com/git/git/blob/master/Documentation/RelNotes/2.35.0.txt#L74-L75
Lefthook version
1.5.2
Steps to reproduce
Commit something in a dir with unstaged changes.
Expected results
No problems, remporarily stashed unstaged changes applied back cleanly.
Actual results
Couldn't restore hidden unstaged files: exit status 129
Possible Solution
Logs / Screenshots
LEFTHOOK_VERBOSE=true git ...
[...]
โ [lefthook] cmd: [git apply -v --whitespace=nowarn --recount --unidiff-zero --allow-empty .git/info/lefthook-unstaged.patch]
โ [lefthook] dir: [...]
โ [lefthook] err: exit status 129
โ [lefthook] out: error: unknown option `allow-empty'
usage: git apply [<options>] [<patch>...]
[...]
Wow, that's bad. Thank you for creating an issue. I would never get this error, since I currently have git 2.39.
For an additional datapoint, also hit this with Ubuntu 20, git 2.25.1
Seems like this was merged to 1.4.10 so for a quick workaround, downgrading to 1.4.9 works; go install github.com/evilmartians/lefthook@v1.4.9
.
On a quick check at repology, looks like this will be hitting also Alpine up to 3.15, CentOS up to 8, Debian up to 11, Fedora up to 34, along with the already reported Ubuntus up to 22.
ps. ๐ @scop
Seems like a fix is out in 1.5.4, thanks for the quick turnaround and great piece of software @mrexox !
Seconded! ๐