Skip to content

Commit

Permalink
fix: handle nonexistent git hooks directory
Browse files Browse the repository at this point in the history
Summary:
It is possible for a .git subdirectory of a repository to not contain
the default hooks/ directory (perhaps the user deleted it, for example).

In this situation, we should just gracefully recreate it, rather than
dying.

Test Plan: delete .git/hooks in test repository, verify ka-clone —repair fixes it.

Reviewers: ethan, csilvers

Reviewed By: csilvers

Subscribers: anastassia

Differential Revision: https://phabricator.khanacademy.org/D18826
  • Loading branch information
Matthew Rothenberg committed Jun 23, 2015
1 parent bee838e commit 183fa61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/ka-clone
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ def install_commit_linter():
def _install_git_hook(template_name, hook_name):
"""Install a template as an executable git hook."""
src = os.path.join(TEMPLATES_DIR, template_name)
dst = os.path.join(os.getcwd(), ".git", "hooks", hook_name)
shutil.copy(src, dst)
hooks_dir = os.path.join(os.getcwd(), ".git", "hooks")
if not os.path.isdir(hooks_dir):
os.makedirs(hooks_dir)
dst = os.path.join(hooks_dir, hook_name)
shutil.copyfile(src, dst)
os.chmod(dst, (os.stat(dst)).st_mode | 0111) # ensure chmod +x


Expand Down

0 comments on commit 183fa61

Please sign in to comment.