| 33 | |
| 34 | class CmdPostCheckout(CmdHookBase): |
| 35 | def _run(self): |
| 36 | # when we are running from pre-commit tool, it doesn't provide CLI |
| 37 | # flags, but instead provides respective env vars that we could use. |
| 38 | flag = os.environ.get("PRE_COMMIT_CHECKOUT_TYPE") |
| 39 | if flag is None and len(self.args.args) >= 3: |
| 40 | # see https://git-scm.com/docs/githooks#_post_checkout |
| 41 | flag = self.args.args[2] |
| 42 | |
| 43 | # checking out some reference and not specific file. |
| 44 | if flag != "1": |
| 45 | return 0 |
| 46 | |
| 47 | # make sure we are not in the middle of a rebase/merge, so we |
| 48 | # don't accidentally break it with an unsuccessful checkout. |
| 49 | # Note that git hooks are always running in repo root. |
| 50 | if os.path.isdir(os.path.join(".git", "rebase-merge")): |
| 51 | return 0 |
| 52 | |
| 53 | from dvc.cli import main |
| 54 | |
| 55 | return main(["checkout"]) |
| 56 | |
| 57 | |
| 58 | class CmdPrePush(CmdHookBase): |