Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygit2
- import sys
- import subprocess
- import re
- from giturlparse import parse as giturlparse
- TOKEN_USER = b'x-oauth-basic'
- def get_credentials(remote):
- p = giturlparse(remote.url)
- out = subprocess.check_output([
- 'security', 'find-internet-password',
- '-r', 'htps',
- '-s', p.domain,
- '-p', '',
- '-g',
- ], stderr=subprocess.STDOUT)
- username = re.search(rb'"acct"<blob>="([^"]+)"', out)
- username = username.group(1)
- password = re.search(rb'password: "([^"]+)"', out)
- password = password.group(1)
- if password == TOKEN_USER:
- username, password = password, username
- return pygit2.UserPass(username, password)
- remote_name = sys.argv[1]
- branch_name = sys.argv[2]
- repo = pygit2.Repository('./.git')
- remote = repo.remotes[remote_name]
- branch = repo.lookup_branch(branch_name)
- print(remote)
- print(branch.name)
- remote.credentials = get_credentials(remote)
- remote.push([branch.name])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement