Skip to content

Stash changes before running pre-commit #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
finnhodgkin opened this issue Oct 12, 2017 · 7 comments
Closed

Stash changes before running pre-commit #12

finnhodgkin opened this issue Oct 12, 2017 · 7 comments

Comments

@finnhodgkin
Copy link
Collaborator

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.

bb4242 pushed a commit to bb4242/elixir-pre-commit that referenced this issue Jun 4, 2018
This addresses dwyl#12, where broken code could pass through the pre-commit checks.
bb4242 pushed a commit to bb4242/elixir-pre-commit that referenced this issue Jun 4, 2018
This addresses dwyl#12, where broken code could pass through the pre-commit checks.
@DenisGorbachev
Copy link

Doesn't work with git version 1.9.1: stash command doesn't have push subcommand.

starfall@nx:~/workspace/leverex$ git commit
Pre-commit running...
usage: git stash list [<options>]
   or: git stash show [<stash>]
   or: git stash drop [-q|--quiet] [<stash>]
   or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
   or: git stash branch <branchname> [<stash>]
   or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
		       [-u|--include-untracked] [-a|--all] [<message>]]
   or: git stash clear
** (MatchError) no match of right hand side value: {"", 1}
    lib/mix/tasks/pre_commit.ex:18: Mix.Tasks.PreCommit.run/1
    (mix) lib/mix/task.ex:314: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
    (elixir) lib/code.ex:677: Code.require_file/2
starfall@nx:~/workspace/leverex$ git --version
git version 1.9.1

@jdav-dev
Copy link

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)

@ZooeyMiller
Copy link
Collaborator

ZooeyMiller commented Jul 19, 2018

Can we close this issue now that #30 is merged? @finnhodgkin

@jdav-dev
Copy link

I've opened #32 with my comment so it can be tracked on its own.

@iteles
Copy link
Member

iteles commented Jul 20, 2018

@ZooeyMiller I'm with @finnhodgkin now and will nudge 😊

@secondspass
Copy link

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).

@ZooeyMiller
Copy link
Collaborator

@secondspass Thanks for letting us know! I'll add required git version to the docs as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants