Last active
August 29, 2015 14:16
-
-
Save GaretJax/7aafd1156afc1352c6ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygit2 | |
import sys | |
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 = pygit2.KeypairFromAgent('git') | |
remote.push([branch.name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment