{"action":"created","issue":{"url":"https://api.github.com/repos/pre-commit/pre-commit/issues/214","labels_url":"https://api.github.com/repos/pre-commit/pre-commit/issues/214/labels{/name}","comments_url":"https://api.github.com/repos/pre-commit/pre-commit/issues/214/comments","events_url":"https://api.github.com/repos/pre-commit/pre-commit/issues/214/events","html_url":"https://github.com/pre-commit/pre-commit/issues/214","id":64286647,"number":214,"title":"Not stashing changes before installing","user":{"login":"quentindemetz","id":2451971,"avatar_url":"https://avatars.githubusercontent.com/u/2451971?v=3","gravatar_id":"","url":"https://api.github.com/users/quentindemetz","html_url":"https://github.com/quentindemetz","followers_url":"https://api.github.com/users/quentindemetz/followers","following_url":"https://api.github.com/users/quentindemetz/following{/other_user}","gists_url":"https://api.github.com/users/quentindemetz/gists{/gist_id}","starred_url":"https://api.github.com/users/quentindemetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quentindemetz/subscriptions","organizations_url":"https://api.github.com/users/quentindemetz/orgs","repos_url":"https://api.github.com/users/quentindemetz/repos","events_url":"https://api.github.com/users/quentindemetz/events{/privacy}","received_events_url":"https://api.github.com/users/quentindemetz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-25T14:43:13Z","updated_at":"2015-03-25T15:17:00Z","closed_at":null,"body":"Hi,\r\n\r\nI'm regularly running into this situation: I have pending changes, I run `git commit -a`, and pre-commit tries to install its hooks:\r\n```\r\n[INFO] Initializing environment for git://github.com/pre-commit/pre-commit-hooks.\r\nAn unexpected error has occurred: CalledProcessError: Command: ['git', 'checkout', 'd3db0385825d4c082bc7117c090ac16cb4840f3e']\r\nReturn code: 1\r\nExpected return code: 0\r\nOutput: (none)\r\nErrors: \r\n    error: Your local changes to the following files would be overwritten by checkout:\r\n        .pre-commit-config.yaml\r\n        .travis.yml\r\n        CHANGELOG\r\n        README.md\r\n        hooks.yaml\r\n        pre_commit_hooks/autopep8_wrapper.py\r\n        pre_commit_hooks/check_json.py\r\n        pre_commit_hooks/check_yaml.py\r\n        pre_commit_hooks/debug_statement_hook.py\r\n        pre_commit_hooks/end_of_file_fixer.py\r\n        pre_commit_hooks/tests_should_end_in_test.py\r\n        pre_commit_hooks/trailing_whitespace_fixer.py\r\n        pre_commit_hooks/util.py\r\n        pylintrc\r\n        requirements-dev.txt\r\n        setup.py\r\n        testing/util.py\r\n        tests/autopep8_wrapper_test.py\r\n        tests/debug_statement_hook_test.py\r\n        tests/end_of_file_fixer_test.py\r\n        tests/tests_should_end_in_test_test.py\r\n        tests/trailing_whitespace_fixer_test.py\r\n        tests/util_test.py\r\n        tox.ini\r\n    Please, commit your changes or stash them before you can switch branches.\r\n    Aborting\r\n    \r\n\r\nCheck the log at ~/.pre-commit/pre-commit.log\r\n```\r\n\r\nThe log contents are \r\n```\r\nAn unexpected error has occurred: CalledProcessError: Command: ['git', 'checkout', 'd3db0385825d4c082bc7117c090ac16cb4840f3e']\r\nReturn code: 1\r\nExpected return code: 0\r\nOutput: (none)\r\nErrors: \r\n    error: Your local changes to the following files would be overwritten by checkout:\r\n    \t.pre-commit-config.yaml\r\n    \t.travis.yml\r\n    \tCHANGELOG\r\n    \tREADME.md\r\n    \thooks.yaml\r\n    \tpre_commit_hooks/autopep8_wrapper.py\r\n    \tpre_commit_hooks/check_json.py\r\n    \tpre_commit_hooks/check_yaml.py\r\n    \tpre_commit_hooks/debug_statement_hook.py\r\n    \tpre_commit_hooks/end_of_file_fixer.py\r\n    \tpre_commit_hooks/tests_should_end_in_test.py\r\n    \tpre_commit_hooks/trailing_whitespace_fixer.py\r\n    \tpre_commit_hooks/util.py\r\n    \tpylintrc\r\n    \trequirements-dev.txt\r\n    \tsetup.py\r\n    \ttesting/util.py\r\n    \ttests/autopep8_wrapper_test.py\r\n    \ttests/debug_statement_hook_test.py\r\n    \ttests/end_of_file_fixer_test.py\r\n    \ttests/tests_should_end_in_test_test.py\r\n    \ttests/trailing_whitespace_fixer_test.py\r\n    \ttests/util_test.py\r\n    \ttox.ini\r\n    Please, commit your changes or stash them before you can switch branches.\r\n    Aborting\r\n    \r\n\r\nTraceback (most recent call last):\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/error_handler.py\", line 34, in error_handler\r\n    yield\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/main.py\", line 129, in main\r\n    return run(runner, args)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/commands/run.py\", line 165, in run\r\n    return _run_hooks(runner, args, write=write, environ=environ)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/commands/run.py\", line 115, in _run_hooks\r\n    for repo in runner.repositories:\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/runner.py\", line 43, in repositories\r\n    repository.require_installed()\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/repository.py\", line 64, in require_installed\r\n    self.install()\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/repository.py\", line 78, in install\r\n    for language_name, _ in self.languages\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/repository.py\", line 41, in languages\r\n    for _, hook in self.hooks\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/repository.py\", line 49, in hooks\r\n    for hook in self.repo_config['hooks']\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/repository.py\", line 49, in <genexpr>\r\n    for hook in self.repo_config['hooks']\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/manifest.py\", line 24, in hooks\r\n    return dict((hook['id'], hook) for hook in self.manifest_contents)\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/manifest.py\", line 18, in manifest_contents\r\n    self.repo_path_getter.repo_path, C.MANIFEST_FILE,\r\n  File \"/usr/lib/python3.4/site-packages/cached_property.py\", line 26, in __get__\r\n    value = obj.__dict__[self.func.__name__] = self.func(obj)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/store.py\", line 46, in repo_path\r\n    return self._store.clone(self._repo, self._sha)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/store.py\", line 119, in clone\r\n    cmd_output('git', 'checkout', sha)\r\n  File \"/home/qdm/workspace/web/pre-commit/pre_commit/util.py\", line 160, in cmd_output\r\n    returncode, cmd, retcode, output=(stdout, stderr),\r\npre_commit.util.CalledProcessError: Command: ['git', 'checkout', 'd3db0385825d4c082bc7117c090ac16cb4840f3e']\r\nReturn code: 1\r\nExpected return code: 0\r\nOutput: (none)\r\nErrors: \r\n    error: Your local changes to the following files would be overwritten by checkout:\r\n    \t.pre-commit-config.yaml\r\n    \t.travis.yml\r\n    \tCHANGELOG\r\n    \tREADME.md\r\n    \thooks.yaml\r\n    \tpre_commit_hooks/autopep8_wrapper.py\r\n    \tpre_commit_hooks/check_json.py\r\n    \tpre_commit_hooks/check_yaml.py\r\n    \tpre_commit_hooks/debug_statement_hook.py\r\n    \tpre_commit_hooks/end_of_file_fixer.py\r\n    \tpre_commit_hooks/tests_should_end_in_test.py\r\n    \tpre_commit_hooks/trailing_whitespace_fixer.py\r\n    \tpre_commit_hooks/util.py\r\n    \tpylintrc\r\n    \trequirements-dev.txt\r\n    \tsetup.py\r\n    \ttesting/util.py\r\n    \ttests/autopep8_wrapper_test.py\r\n    \ttests/debug_statement_hook_test.py\r\n    \ttests/end_of_file_fixer_test.py\r\n    \ttests/tests_should_end_in_test_test.py\r\n    \ttests/trailing_whitespace_fixer_test.py\r\n    \ttests/util_test.py\r\n    \ttox.ini\r\n    Please, commit your changes or stash them before you can switch branches.\r\n    Aborting\r\n```\r\n\r\nI think this is a regression from a previous version, it was more seamless then."},"comment":{"url":"https://api.github.com/repos/pre-commit/pre-commit/issues/comments/86079181","html_url":"https://github.com/pre-commit/pre-commit/issues/214#issuecomment-86079181","issue_url":"https://api.github.com/repos/pre-commit/pre-commit/issues/214","id":86079181,"user":{"login":"asottile","id":1810591,"avatar_url":"https://avatars.githubusercontent.com/u/1810591?v=3","gravatar_id":"","url":"https://api.github.com/users/asottile","html_url":"https://github.com/asottile","followers_url":"https://api.github.com/users/asottile/followers","following_url":"https://api.github.com/users/asottile/following{/other_user}","gists_url":"https://api.github.com/users/asottile/gists{/gist_id}","starred_url":"https://api.github.com/users/asottile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asottile/subscriptions","organizations_url":"https://api.github.com/users/asottile/orgs","repos_url":"https://api.github.com/users/asottile/repos","events_url":"https://api.github.com/users/asottile/events{/privacy}","received_events_url":"https://api.github.com/users/asottile/received_events","type":"User","site_admin":false},"created_at":"2015-03-25T15:17:00Z","updated_at":"2015-03-25T15:17:00Z","body":"Hmmm that is odd!\r\n\r\nCan you supply the following:\r\n\r\n```\r\n$ git --version\r\n$ pre-commit --version\r\n```\r\n\r\nAnd potentially can you cd to that directory and see what `git status` is?  (The directory might be hard to find... hmm...)\r\n\r\nYou can find it by doing the following:\r\n\r\n```\r\n$ sqlite3 ~/.pre-commit/db.db 'SELECT path FROM repos WHERE repo = \"git url for repo\" AND ref = \"sha you are using\"'\r\n```\r\n\r\nAlso I'm curious if `pre-commit clean` will fix it (obviously not a solution as I'd like to prevent getting into this situation).\r\n\r\nI have some ideas on how to fix it if it's just that git changed how `--no-checkout` + `checkout` works\r\n"}}