Skip to content
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

Make pre push hook executable #7111

Merged
merged 2 commits into from
Jul 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make pre-push hook file executable
  • Loading branch information
apb7 committed Jul 8, 2019
commit ce20ba983d93624322eb391ca7d5cbdb2b344e32
32 changes: 23 additions & 9 deletions scripts/pre_push_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,34 @@ def _has_uncommitted_files():


def _install_hook():
"""Installs the pre_push_hook script. It ensures that oppia is root."""
"""Installs the pre_push_hook script and makes it executable.
It ensures that oppia/ is the root folder.

Raises:
ValueError if chmod command fails.
"""
oppia_dir = os.getcwd()
hooks_dir = os.path.join(oppia_dir, '.git', 'hooks')
pre_push_file = os.path.join(hooks_dir, 'pre-push')
chmod_cmd = ['chmod', '+x', pre_push_file]
if os.path.islink(pre_push_file):
print 'Symlink already exists'
return
try:
os.symlink(os.path.abspath(__file__), pre_push_file)
print 'Created symlink in .git/hooks directory'
# Raises AttributeError on windows, OSError added as failsafe.
except (OSError, AttributeError):
shutil.copy(__file__, pre_push_file)
print 'Copied file to .git/hooks directory'
else:
try:
os.symlink(os.path.abspath(__file__), pre_push_file)
print 'Created symlink in .git/hooks directory'
# Raises AttributeError on windows, OSError added as failsafe.
except (OSError, AttributeError):
shutil.copy(__file__, pre_push_file)
print 'Copied file to .git/hooks directory'

print 'Making pre-push hook file executable ...'
_, err_chmod_cmd = _start_subprocess_for_result(chmod_cmd)

if not err_chmod_cmd:
print 'pre-push hook file is now executable!'
else:
raise ValueError(err_chmod_cmd)


def does_diff_include_js_or_ts_files(files_to_lint):
Expand Down