Skip to content

Commit

Permalink
Add pre-push git hook to prevent pushing to yugabyte repo
Browse files Browse the repository at this point in the history
Summary:
1) Add hooks/ directory
2) Add pre-push python script

Test Plan:
```
ln -s hooks/pre-push .git/hooks/pre-push
ybd --sj
touch fakefile
git commit -am "test"
```
Attempt to push to yugabyte/{branch} and it should fail
Attempt to push to {other-repo}/{branch} and it should succeed

To test that this does not block `arc land`, we will see if landing this diff is successful..

Jenkins: skip

Reviewers: mikhail, jason

Reviewed By: mikhail, jason

Subscribers: devops

Differential Revision: https://phabricator.dev.yugabyte.com/D8957
  • Loading branch information
robertsami committed Jul 31, 2020
1 parent 60775ba commit c91df34
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

import sys

def run_pre_push_hook(remote_loc, remote_ref):
has_github = "github.com" in remote_loc.lower()
has_yb_repo = "yugabyte/yugabyte-db" in remote_loc.lower()
is_master_push = remote_ref == "refs/heads/master"

if has_github and has_yb_repo and not is_master_push:
sys.stderr.write(
"Cannot push any branch except master to yugabyte/yugabyte-db repo, "
"which should only be done when running arc land.")
return 1
return 0

if __name__ == "__main__":
[remote_name, remote_loc] = sys.argv[1], sys.argv[2]
[local_ref, local_sha1, remote_ref, remote_sha1] = sys.stdin.read().split()
sys.exit(run_pre_push_hook(remote_loc, remote_ref))

0 comments on commit c91df34

Please sign in to comment.