本文整理汇总了Python中dulwich.porcelain.push方法的典型用法代码示例。如果您正苦于以下问题:Python porcelain.push方法的具体用法?Python porcelain.push怎么用?Python porcelain.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dulwich.porcelain
的用法示例。
在下文中一共展示了porcelain.push方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit_and_push
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def commit_and_push(
version: str,
repository: Repository,
paths: List[Path],
) -> None:
"""
Commit and push all changes.
"""
local_repository = Repo('.')
_, ignored = add(paths=[str(path) for path in paths])
assert not ignored
message = b'Update for release ' + version.encode('utf-8')
commit(message=message)
branch_name = 'master'
push(
repo=local_repository,
remote_location=repository.ssh_url,
refspecs=branch_name.encode('utf-8'),
)
示例2: upload
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def upload(self, cmd: str, meta: dict):
"""Push the current state of the registry to Git."""
index = os.path.join(self.cached_repo, self.INDEX_FILE)
if os.path.exists(index):
os.remove(index)
self._log.info("Writing the new index.json ...")
with open(index, "w") as _out:
json.dump(self.contents, _out, sort_keys=True, indent=4)
git.add(self.cached_repo, [index])
message = self.COMMIT_MESSAGES[cmd].format(**meta)
if self.signoff:
global_conf_path = os.path.expanduser("~/.gitconfig")
if os.path.exists(global_conf_path):
with open(global_conf_path, "br") as _in:
conf = ConfigFile.from_file(_in)
try:
name = conf.get(b"user", b"name").decode()
email = conf.get(b"user", b"email").decode()
message += self.DCO_MESSAGE.format(name=name, email=email)
except KeyError:
self._log.warning(
"Did not find name or email in %s, committing without DCO",
global_conf_path)
else:
self._log.warning("Global git configuration file %s does not exist, "
"committing without DCO", global_conf_path)
else:
self._log.info("Committing the index without DCO")
git.commit(self.cached_repo, message=message)
self._log.info("Pushing the updated index ...")
# TODO: change when https://github.com/dulwich/dulwich/issues/631 gets addressed
git.push(self.cached_repo, self.remote_url, b"master")
if self._are_local_and_remote_heads_different():
self._log.error("Push has failed")
raise ValueError("Push has failed")
示例3: git_checkout
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def git_checkout(args):
if len(args) in [1, 2]:
repo = _get_repo()
_confirm_dangerous()
if os.path.exists(os.path.join(repo.repo.controldir(), 'MERGE_HEAD')):
#just cancel in progress merge
os.remove(os.path.join(repo.repo.controldir(), 'MERGE_HEAD'))
os.remove(os.path.join(repo.repo.controldir(), 'MERGE_MSG'))
if len(args) == 1:
branchname = args[0]
if branchname in repo.branches:
branch_ref = repo._format_ref_branch(branchname)
repo.repo.refs.set_symbolic_ref('HEAD', branch_ref)
repo.checkout_all()
repo.switch_branch('{0}'.format(args[0]))
#Temporary hack to get create branch into source
#TODO: git functions should probably all user parseargs, like git push
if len(args) == 2:
if args[0] == '-b':
#TODO: Add tracking as a parameter
print("Creating branch {0}".format(args[1]))
repo.create_branch(repo.active_branch, args[1], tracking=None)
#Recursive call to checkout the branch we just created
git_checkout([args[1]])
else:
refresh_editor()
else:
print(command_help['checkout'])
示例4: push
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def push(self, repo_user, repo_pass, repo_remote, repo_branch):
"""Push the current commit to git."""
try:
porcelain.push(self.repo, "https://{}:{}@{}".format(repo_user,
repo_pass, repo_remote), bytes(repo_branch, "utf-8"))
except dulwich.errors.GitProtocolError:
raise InvalidCommand(
"Upload file failed: GitProtocolError - Check your username and password in the git configuration...")
except KeyError:
raise InvalidCommand("Upload file failed: KeyError - Check your git configuration for missing keys...")
except TypeError:
raise InvalidCommand("Upload file failed: TypeError - Did you forget to create a git configuration?")
except Exception:
log.exception("GitHandler::push()")
raise InvalidCommand("Upload file failed: Unknown - Please check your log files...")
示例5: push_code_update
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def push_code_update(c, git_ref):
"""
Synchronize the remote code repository
"""
with c.conn.cd(c.conn.project_root):
# First, check that the remote deployment directory exists
try:
c.conn.run("test -d .", hide=True)
except UnexpectedExit:
raise Exit(
"Provisioning not finished, directory {} doesn't exist!".format(
c.config["root"]
)
)
# Now make sure there's git, and a git repository
try:
c.conn.git("--version", hide=True)
except UnexpectedExit:
raise Exit("Provisioning not finished, git not available!")
try:
c.conn.git("rev-parse --git-dir", hide=True)
except UnexpectedExit:
c.conn.git("init")
git_remote_url = "ssh://{user}@{host}:{port}/{directory}".format(
user=c.conn.user,
host=c.conn.host,
port=c.conn.port,
directory=c.conn.project_root,
)
# Delete the FABHEAD branch
with c.conn.cd(c.conn.project_root):
try:
c.conn.git("branch -D FABHEAD", hide=True)
except UnexpectedExit:
pass
c.conn.git("checkout -f -B FABHEAD master", hide=True)
# Now push our code to the remote, always as FABHEAD branch
porcelain.push(".", git_remote_url, "{}:FABHEAD".format(git_ref), force=True)
c.conn.git("checkout -f -B master FABHEAD", hide=True)
c.conn.git("submodule update --init", hide=True)
示例6: git_fetch
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def git_fetch(args):
parser = argparse.ArgumentParser(
prog='git fetch',
usage='git fetch [http(s)://<remote repo> or remotename] [-u username[:password]]',
description="Push to a remote repository"
)
parser.add_argument('url', type=str, nargs='?', help='URL to push to')
parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]')
result = parser.parse_args(args)
repo = _get_repo()
origin = 'origin'
if not result.url:
result.url = repo.remotes.get('origin', '')
if result.url in repo.remotes:
origin = result.url
result.url = repo.remotes.get(origin)
if not urlparse(result.url).scheme:
raise Exception('url must match a remote name, or must start with http:// or https://')
print('Starting fetch, this could take a while')
remote_refs = porcelain.fetch(repo.repo.path, result.url)
print('Fetch successful. Importing refs')
remote_tags = gittle.utils.git.subrefs(remote_refs, 'refs/tags')
remote_heads = gittle.utils.git.subrefs(remote_refs, 'refs/heads')
# Filter refs
clean_remote_tags = gittle.utils.git.clean_refs(remote_tags)
clean_remote_heads = gittle.utils.git.clean_refs(remote_heads)
# Base of new refs
heads_base = 'refs/remotes/' + origin
# Import branches
repo.import_refs(heads_base, clean_remote_heads)
for k, v in clean_remote_heads.items():
print('imported {}/{} {}'.format(heads_base, k, v))
# Import tags
repo.import_refs('refs/tags', clean_remote_tags)
for k, v in clean_remote_tags.items():
print('imported {}/{} {}'.format('refs/tags', k, v))
print('Checking for deleted remote refs')
#delete unused remote refs
for k in gittle.utils.git.subrefs(repo.refs, heads_base):
if k not in clean_remote_heads:
print('Deleting {}'.format('/'.join([heads_base, k])))
del repo.refs['/'.join([heads_base, k])]
print('Fetch complete')
示例7: push_action
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import push [as 别名]
def push_action(self,sender):
# pdb.set_trace()
user, sep, pw = (None,None,None)
repo = self._get_repo()
remote=self.view['remote'].text
if remote in self.remotes_iterator():
remote = repo.remotes.get(remote,'')
branch_name = os.path.join('refs','heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch
# tODO use remote branch_name
netloc = urlparse.urlparse(remote).netloc
keychainservice = 'shellista.git.{0}'.format(netloc)
#define some callbacks for use by uidialog
def push_callback(user,pw):
print "Attempting to push to: {0}, branch: {1}".format(remote, branch_name)
console.show_activity()
if user:
try:
parsedurl=urlparse.urlparse(remote)
host_with_auth='{}:{}@{}'.format(
user,pw,parsedurl.netloc)
url=urlparse.urlunparse(
parsedurl._replace( netloc=host_with_auth))
porcelain.push(repo.path, url, branch_name)
keychain.set_password(keychainservice, user, pw)
except urllib2.URLError:
console.hide_activity()
console.hud_alert('push failed','error')
return
else:
porcelain.push(repo.repo, result.url, branch_name)
console.hide_activity()
console.hud_alert('push complete')
def push_callback_dict(d):
push_callback(d['username'],d['password'])
#Attempt to retrieve user
try:
user = dict(keychain.get_services())[keychainservice]
pw = keychain.get_password(keychainservice, user)
if pw:
push_callback(user,pw)
else:
raise KeyError
except KeyError:
self.get_pass(netloc,push_callback_dict)