SHARE
TWEET

Untitled

a guest Apr 19th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # Author: Rahul Gopinath <rahul@gopinath.org>
  3. # LICENSE : GPLv3
  4. # DESC: This post-commit hook enables one to save generated files
  5. #       seprately from the main repository.
  6. # REQUIREMENTS:
  7. # * Place this file as .git/hooks/post-commit (without the extension)
  8. #   and make sure it is executable `chmod +x .git/hooks/post-commit`
  9. # * Define your backup dir as environment variable `BACKUP_DIR` i.e
  10. #   `export BACKUP_DIR=~/my_backups`
  11. # * If you prefer not to backup your entire workspace, define what
  12. #   files you need backed up in file `.git/precious.txt` This can
  13. #   be either files or folders.
  14. # * Your backup files are saved with the corresponding sha to the
  15. #   filesystem directory specified. You may wish to change it to RSYNC
  16. #   or ftp to an offsite location or even create a github repo
  17. #   specifically for binary files if they are important.
  18.  
  19. import subprocess
  20. import sys
  21. import os
  22. import glob
  23. import tarfile
  24.  
  25. def main():
  26.     try:
  27.         sha = subprocess.check_output(['git','rev-parse','HEAD']).strip().decode()
  28.         backup_dir = os.environ.get('BACKUP_DIR', '/tmp')
  29.         if os.path.isfile('.git/precious.txt'):
  30.             with  open('.git/precious.txt') as f:
  31.                 backup_files = [line.strip() for line in f if line.strip()]
  32.         else:
  33.             backup_files = glob.glob('./*')
  34.         with tarfile.open('%s/%s.tar.gz' % (backup_dir, sha), 'w:gz') as tar:
  35.             for name in backup_files:
  36.                 tar.add(name)
  37.     except subprocess.CalledProcessError as err:
  38.         print("Exec failed:", err)
  39.         sys.exit(-1)
  40.  
  41. if __name__ == "__main__":
  42.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top