本文整理汇总了Python中git.Repo.create_remote方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.create_remote方法的具体用法?Python Repo.create_remote怎么用?Python Repo.create_remote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.create_remote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feedstocks_clone_all_handle_args
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def feedstocks_clone_all_handle_args(args):
for repo in feedstock_repos(args.organization):
clone_directory = os.path.join(args.feedstocks_directory, repo.name)
if not os.path.exists(clone_directory):
print('Cloning {}'.format(repo.name))
new_repo = Repo.clone_from(repo.ssh_url, clone_directory)
clone = Repo(clone_directory)
if 'upstream' in [remote.name for remote in clone.remotes]:
clone.delete_remote('upstream')
clone.create_remote('upstream', url=repo.ssh_url)
示例2: clone_feedstock
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def clone_feedstock(feedstock_gh_repo, feedstocks_dir):
repo = feedstock_gh_repo
clone_directory = os.path.join(feedstocks_dir, repo.name)
if not os.path.exists(clone_directory):
print('Cloning {}'.format(repo.name))
new_repo = Repo.clone_from(repo.ssh_url, clone_directory)
clone = Repo(clone_directory)
if 'upstream' in [remote.name for remote in clone.remotes]:
clone.delete_remote('upstream')
clone.create_remote('upstream', url=repo.ssh_url)
示例3: update_data
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def update_data(repo: Repo, repo_addr: str):
"""Updates given git repo.
Args:
repo: Git data repo.
repo_addr: url address of the repo
"""
logging.info(f'Updating repo in {repo.working_dir}')
if 'origin' not in [r.name for r in repo.remotes]:
repo.create_remote('origin', repo_addr)
repo.remotes.origin.fetch('+refs/heads/*:refs/remotes/origin/*')
repo.remotes.origin.pull()
示例4: _open_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def _open_repo(self, repo_dir, upstream_url):
# Split things out into multiple steps and checks to be Ctrl-c resilient
if os.path.isdir(repo_dir):
repo = Repo(repo_dir)
else:
repo = Repo.init(repo_dir)
try:
repo.remotes.origin
except AttributeError:
repo.create_remote('origin', upstream_url)
return repo
示例5: checkout
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def checkout(self, commit='master'):
# If commit is none, we'll get the latest
try:
repo = Repo(self.local_path)
except NoSuchPathError:
# I guess it was never cloned...
repo = Repo.init(self.local_path)
repo.create_remote('origin', url=self.url)
repo.remotes.origin.fetch()
bare_master = repo.create_head('master', repo.remotes.origin.refs.master)
repo.head.set_reference(bare_master)
repo.head.reset(index=True, working_tree=True)
return repo
示例6: fetch_clicked
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def fetch_clicked(self):
"""
When the Fetch button is clicked, we fetch the remote references.
"""
a_repo = Repo(self._directory)
remote_url = unicode(self._ui.locationLineEdit.text())
if remote_url in self._existing_remotes:
self._remote = a_repo.remotes[self._existing_remotes[remote_url]]
else:
id = 0
available_name = "remote" + str(id)
while available_name in self._existing_remotes.values():
id += 1
available_name = "remote" + str(id)
self._remote = a_repo.create_remote(available_name, remote_url)
self._remote.fetch()
self._created_remotes.append(self._remote)
# When fetching a second time, we will only have the branches
fetch_refs = self._remote.fetch()
self._ui.branchComboBox.clear()
for fetch_info in fetch_refs:
self._ui.branchComboBox.insertItem(0, fetch_info.name)
self._ui.branchComboBox.insertItem(0, QString(""))
self._ui.branchComboBox.setCurrentIndex(0)
self.branch_mode()
示例7: rebase
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def rebase(self, issue, branch=None):
if not issue.pull_request:
return "Rebase is just supported in PR for now"
pr = issue.repository.get_pull(issue.number)
branch_name = pr.head.ref
branched_sdk_id = pr.head.repo.full_name+'@'+branch_name
upstream_url = 'https://github.com/{}.git'.format(pr.base.repo.full_name)
upstream_base = pr.base.ref if not branch else branch
with tempfile.TemporaryDirectory() as temp_dir, \
manage_git_folder(self.gh_token, Path(temp_dir) / Path("sdk"), branched_sdk_id) as sdk_folder:
sdk_repo = Repo(str(sdk_folder))
configure_user(self.gh_token, sdk_repo)
upstream = sdk_repo.create_remote('upstream', url=upstream_url)
upstream.fetch()
msg = sdk_repo.git.rebase('upstream/{}'.format(upstream_base))
_LOGGER.debug(msg)
msg = sdk_repo.git.push(force=True)
_LOGGER.debug(msg)
return "Rebase done and pushed to the branch"
示例8: _initialise_git_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def _initialise_git_repo(self):
'''
Get a fresh initialised Repo object
'''
repo = Repo(str(self._staging_git_path))
main_remote = repo.remotes[self.REMOTE_NAME]
if main_remote.exists():
config_writer = main_remote.config_writer
config_writer.set('url', self._git_uri)
config_writer.release()
else:
repo.create_remote(self.REMOTE_NAME, self._git_uri)
self.log.debug('Initialise with repo: %r', repo)
return repo
示例9: commit
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def commit(repo_path, remote_repo_url, remote_repo_name):
try:
repo = Repo(repo_path, odbt=GitCmdObjectDB)
#repo.index.add(crawl_paths)
except InvalidGitRepositoryError:
#FIXME: try clone first
repo = Repo.init(repo_path)
try:
origin = repo.remotes[remote_repo_name]
except IndexError:
origin = repo.create_remote(remote_repo_name, remote_repo_url)
logger.debug('repo working dir %s' % repo.working_dir)
#with repo.git.custom_environment(GIT_SSH=GIT_SSH_COMMAND):
origin.pull(RULES_REPO_BRANCH)
repo.index.add('*')
logger.debug('added files to repo')
commit_msg = "Crawl completed at " + time.strftime("%Y-%m-%d-%H-%M-%S")
environ["GIT_AUTHOR_NAME"] = GIT_AUTHOR_NAME
environ["GIT_AUTHOR_EMAIL"] = GIT_AUTHOR_EMAIL
committed = repo.index.commit(commit_msg)
logger.debug('commited policy data')
logger.debug(committed)
#with repo.git.custom_environment(GIT_SSH=GIT_SSH_COMMAND):
origin.push(RULES_REPO_BRANCH)
示例10: clone
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def clone(self):
if not os.path.exists(self.build_dir):
print(green('Cloning %s into %s' % (self.origin, self.build_dir)))
repo = Repo.init(self.build_dir)
repo.create_remote('origin', self.origin)
else:
print(green('Fetch updates for %s' % self.build_dir))
repo = Repo(self.build_dir)
if repo.remotes.origin.url != self.origin: # update remote if desired
repo.delete_remote(repo.remotes.origin)
repo.create_remote('origin', self.origin)
repo.git.checkout('master', f=True)
repo.remotes.origin.fetch(tags=True)
repo.remotes.origin.pull('master')
return repo
示例11: Pull_git
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def Pull_git():
try:
logging.info( 'Trying to initialize btcnet_info repo')
repo = Repo("btcnet_info")
try:
logging.info('Checking if it has been cloned properly')
repo = repo.clone_from("git://github.com/c00w/btcnet_info.git", 'btcnet_info')
except git.exc.GitCommandError:
logging.info('It has been cloned properly')
except git.exc.GitCommandError:
logging.info( 'Making new btcnet_info repo')
repo = Repo.init("btcnet_info")
logging.info('Cloning into it')
repo = repo.clone_from("git://github.com/c00w/btcnet_info.git", 'btcnet_info')
try:
logging.info('Checking if we need to add the origin')
origin = repo.create_remote('origin', 'git://github.com/c00w/btcnet_info.git')
except git.exc.GitCommandError:
logging.info('We do not need to add the origin')
logging.info( 'Updating btcnet_info')
origin = repo.remotes.origin
origin.fetch()
origin.pull('master')
logging.info( 'Done')
示例12: Pull_git
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def Pull_git():
"""
Tries to load btcnet_info as git repository and download the files
"""
try:
logging.info('Trying to load btcnet_info submodule')
#Try load load btcnet_info as a git repo (Submodule)
repo = Repo("btcnet_info")
except GitCommandError:
# Here we have some sort of error probably an empty directory in a zip download instead of
# A git submodule
logging.info('Making new btcnet_info repo')
repo = Repo.init("btcnet_info")
logging.info('Cloning into it')
repo = repo.clone_from("git://github.com/c00w/btcnet_info.git", 'btcnet_info')
try:
#For some reason the above doesn't always set the origin correctly.
logging.info('Checking if we need to add the origin')
origin = repo.create_remote('origin', 'git://github.com/c00w/btcnet_info.git')
except GitCommandError:
logging.info('We do not need to add the origin')
logging.info('Updating btcnet_info')
#Select the origin
origin = repo.remotes.origin
#Update it
origin.fetch()
#Pull the master branch
origin.pull('master')
logging.info('Done')
示例13: add_remote
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def add_remote(cls, repo: Repo,
remote_git_url: str, remote_name: str=None):
remote_name = remote_name or "origin"
if cls._get_remote(repo, remote_name):
log.warn("Repeatedly adding remote: {}".format(remote_name))
return
return repo.create_remote(remote_name, remote_git_url)
示例14: create_github_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def create_github_repo(args):
token = gh_token()
meta = configure_feedstock.meta_of_feedstock(args.feedstock_directory)
from git import Repo
gh = Github(token)
if args.user is not None:
pass
# User has been defined, and organization has not.
user_or_org = gh.get_user()
else:
# Use the organization provided.
user_or_org = gh.get_organization(args.organization)
repo_name = os.path.basename(os.path.abspath(args.feedstock_directory))
try:
gh_repo = user_or_org.create_repo(
repo_name, has_wiki=False, description="A conda-smithy repository for {}.".format(meta.name())
)
print("Created {} on github".format(gh_repo.full_name))
except GithubException as gh_except:
if gh_except.data.get("errors", [{}])[0].get("message", "") != u"name already exists on this account":
raise
gh_repo = user_or_org.get_repo(repo_name)
print("Github repository already exists.")
# Now add this new repo as a remote on the local clone.
repo = Repo(args.feedstock_directory)
remote_name = args.remote_name.strip()
if remote_name:
if remote_name in [remote.name for remote in repo.remotes]:
existing_remote = repo.remotes[remote_name]
if existing_remote.url != gh_repo.ssh_url:
print(
"Remote {} already exists, and doesn't point to {} "
"(it points to {}).".format(remote_name, gh_repo.ssh_url, existing_remote.url)
)
else:
repo.create_remote(remote_name, gh_repo.ssh_url)
示例15: run
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_remote [as 别名]
def run(self):
os.seteuid(0)
os.setgid(self.gid)
os.setuid(self.uid)
# In case of nonexistent path or empty directory clone the repository.
# Otherwise open it.
try:
if not os.path.exists(self.local) or not os.listdir(self.local):
os.umask(0022)
logger.info("Cloning repo '%s' from '%s' to '%s'" % (self.name, self.remote, self.local))
repo = Repo.clone_from(self.remote, self.local)
else:
logger.info("Loading repo '%s' at '%s'" % (self.name, self.local))
repo = Repo(self.local)
# To make sure our remote is up to date, we delete and create it
# again.
if 'watchgit' in [remote.name for remote in repo.remotes]:
logger.debug("Deleting remote 'watchgit' from repository '%s'" % self.name)
repo.delete_remote('watchgit')
logger.debug("Creating remote '%s' on repository '%s'" % (self.remote, self.name))
remotes = [repo.create_remote('watchgit', self.remote)]
# if all_remotes is set we pull from all remotes
if self.all_remotes is True:
remotes = repo.remotes
# If skip_on_error is true, we don't need to raise a fatal exception.
# Instead we signal our watcher with the exitcode that we failed while
# trying to load the repo.
except Exception as e:
if self.skip_on_error is True:
logger.warn(e, exc_info=1)
os._exit(128)
else:
raise
# Start the watch
logger.info("Starting watch of repository at '%s'" % repo.working_dir)
while True:
logger.debug("Pulling ref '%s' for '%s'" % (self.ref, repo.working_dir))
if self.reset is True and repo.is_dirty():
logger.info("Resetting dirty repository at '%s'" % repo.working_dir)
repo.head.reset(working_tree=True)
for remote in remotes:
logger.debug("Pulling remote '%s'", remote.name)
remote.pull(self.ref)
time.sleep(self.interval)