You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible to sneak broken code through the pre-commit hook by making changes that are saved but not staged with git. Ideally the shell script should stash changes before running pre-commit and then pop the changes back after.
Using git stash push --keep-index as in #30 restores deleted files to the working tree:
$ git init
Initialized empty Git repository in /tmp/git-stash-test/.git/
$ touch test
$ git add -A
$ git commit -m 'initial commit'
[master (root-commit) 5e0577e] initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
$ rm test
$ git add -A
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: test
$ git stash push --keep-index --message pre_commit
Saved working directory and index state On master: pre_commit
$ git stash pop
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: test
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
Dropped refs/stash@{0} (b6658734f4ae35a43bcff3f43b306ea6ae238902)
Hey, just wanted to let you know that git stash push does not exist in git versions older than 2.13. git stash save exists which covers the same ground (but it doesn't have the --message flag).
So if you want it to be backwards compatible, you might want to take another look at it. (Or if you're intending this only for newer versions, disregard this comment).
Activity
Stash working directory before running hooks
Stash working directory before running hooks
DenisGorbachev commentedon Jun 9, 2018
Doesn't work with
git version 1.9.1:stashcommand doesn't havepushsubcommand.jdav-dev commentedon Jul 18, 2018
Using
git stash push --keep-indexas in #30 restores deleted files to the working tree:ZooeyMiller commentedon Jul 19, 2018
Can we close this issue now that #30 is merged? @finnhodgkin
jdav-dev commentedon Jul 19, 2018
I've opened #32 with my comment so it can be tracked on its own.
iteles commentedon Jul 20, 2018
@ZooeyMiller I'm with @finnhodgkin now and will nudge 😊
secondspass commentedon Jul 26, 2018
Hey, just wanted to let you know that
git stash pushdoes not exist in git versions older than 2.13.git stash saveexists which covers the same ground (but it doesn't have the--messageflag).So if you want it to be backwards compatible, you might want to take another look at it. (Or if you're intending this only for newer versions, disregard this comment).
ZooeyMiller commentedon Jul 27, 2018
@secondspass Thanks for letting us know! I'll add required git version to the docs as well.