Skip to content

Commit b4a0159

Browse files
committed
An example of a pre-push hook for this repository
1 parent 9efb072 commit b4a0159

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

hooks/config.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[install.py]
2+
src_dir = os.path.dirname(__file__)
3+
dst_dir = os.path.join(src_dir, '..', '.git', 'hooks')
4+
files = ['pre-push']

hooks/pre-push

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import sys
5+
6+
7+
def main() -> None:
8+
lines = subprocess.check_output(
9+
['git', 'status', '.', '--porcelain'])
10+
if len(str(lines).split('\n')) == 1:
11+
return
12+
print("#####################################################")
13+
print("# Nice! You have changes. Now commit or stash them. #")
14+
print("#####################################################")
15+
subprocess.call(['git', 'status', '.'])
16+
sys.exit(1)
17+
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)