Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import pygit2
  2. import sys
  3. import subprocess
  4. import re
  5. from giturlparse import parse as giturlparse
  6.  
  7.  
  8. TOKEN_USER = b'x-oauth-basic'
  9.  
  10.  
  11. def get_credentials(remote):
  12. p = giturlparse(remote.url)
  13. out = subprocess.check_output([
  14. 'security', 'find-internet-password',
  15. '-r', 'htps',
  16. '-s', p.domain,
  17. '-p', '',
  18. '-g',
  19. ], stderr=subprocess.STDOUT)
  20.  
  21. username = re.search(rb'"acct"<blob>="([^"]+)"', out)
  22. username = username.group(1)
  23.  
  24. password = re.search(rb'password: "([^"]+)"', out)
  25. password = password.group(1)
  26.  
  27. if password == TOKEN_USER:
  28. username, password = password, username
  29.  
  30. return pygit2.UserPass(username, password)
  31.  
  32.  
  33. remote_name = sys.argv[1]
  34. branch_name = sys.argv[2]
  35.  
  36. repo = pygit2.Repository('./.git')
  37. remote = repo.remotes[remote_name]
  38. branch = repo.lookup_branch(branch_name)
  39.  
  40. print(remote)
  41. print(branch.name)
  42.  
  43. remote.credentials = get_credentials(remote)
  44. remote.push([branch.name])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement