本文整理汇总了Python中git.Git.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Git.clone方法的具体用法?Python Git.clone怎么用?Python Git.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.clone方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def run():
jenkins_project = args.projectName
jenkins_build_number = args.buildNumber
if not jenkins.find_if_build_is_green(jenkins_project, jenkins_build_number):
print "Build #" + jenkins_build_number + " of '" + jenkins_project + "' is not a green build."
sys.exit(1)
repo_url = jenkins.find_github_repo_url_from_build(jenkins_project)
git = Git(WORKSPACE, repo_url)
commit_id = jenkins.find_commit_id_from_build(jenkins_project, jenkins_build_number)
verbose("commit_id=" + commit_id)
repo_name = git.repo_name()
verbose("repo_name=" + repo_name)
git.clone()
verbose("Git repo '" + repo_name + "' cloned to " + WORKSPACE)
most_recent_tag = git.describe()
verbose("Most recent release: " + most_recent_tag)
new_version_number = lib.read_user_preferred_version(repo_name, most_recent_tag)
git.tag(commit_id, "release/" + new_version_number)
示例2: sched_builder
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def sched_builder(self):
for project in sorted(Project.get_all(), key=lambda p: p.name):
if (project.name == ""):
continue
try:
log.msg("checking project: %s" % project.name)
if project.is_building():
log.msg("project %s still building, skip" % project.name)
continue
branch = "master"
git = Git(project)
if os.path.isdir(git.workdir):
git.checkout_branch(branch)
git.pull()
else:
git.clone(branch)
if not os.path.isdir(git.workdir):
continue
for remote_branch in git.branches(remote=True):
git.checkout_remote_branch(remote_branch.replace('origin/', ''))
for release in ('stable', 'testing', 'unstable'):
if project.last_tag(release) != git.last_tag(release):
try:
_, version = git.last_tag(release).split('_')
log.msg("new %s tag, building version: %s" % (release, version))
d = threads.deferToThread(self.send_job, project.name, branch, release, version)
except Exception, e:
log.msg("tag not parsed: %s:%s" % (project.name, git.last_tag(release)))
except Exception, e:
log.err(e)
示例3: test_update
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def test_update(self):
git = Git(root_dir_local, test_repo_dir)
git.clone()
self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) != 1)
os.chdir(test_repo_dir)
with open("ANOTHER_FILE.txt", "a") as the_file:
the_file.write("Another file")
lib.call_and_exit_if_failed("git add .")
lib.call_and_exit_if_failed('git commit -m "another commit"')
git.update()
self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) == 1)
示例4: cloneOrCheckout
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def cloneOrCheckout(base_path, repo):
git = Git()
repo_path = os.path.join(base_path, repo['name'])
print (repo_path)
try:
os.chdir(repo_path)
except OSError:
os.chdir(base_path)
git.clone(repo['base_url'] + repo['name'])
os.chdir(repo_path)
cloned = True
finally:
git.fetch()
git.checkout(repo['branch'])
os.chdir(base_path)
示例5: _updateRepo
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def _updateRepo(self, reponame):
remotepath = self.repos.get(reponame, "path")
submodules = self.repos.get(reponame, "submodules") if self.repos.has_option(reponame, "submodules") else False
localpath = os.path.join(self.repodir, reponame)
os.umask(0o007) # create repo content not readable to others
if not os.path.isdir(localpath):
g = Git()
g.clone(remotepath, localpath)
repo = Repo(localpath)
if submodules:
repo.git.submodule("init")
# not-working umask workaround
p = subprocess.Popen(["chmod", "g+w", localpath])
p.wait()
else:
repo = Repo(localpath)
try:
repo.git.update_index("--refresh")
except GitCommandError:
pass # it's fine, we'll reset
# We use wrapped API (direct git command calls) rather than calling semantic GitPython API.
# (e.g. repo.remotes.origin.pull() was replaced by repo.git.pull("origin"))
repo.git.reset("--hard", "master")
# repo.git.clean("-f")
repo.git.pull("origin")
if submodules:
repo.git.submodule("init")
repo.git.submodule("foreach", "git", "fetch")
repo.git.submodule("update")
# now set correct group (same as build user)
usr = self.repos.get(reponame, "build_usr")
p = subprocess.Popen(["chgrp", usr, "-R", localpath])
p.wait()
return repo
示例6: init
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def init(ctx):
"""Run initial setup"""
VerboseLog('Running init()', ctx)
config_file = config_file_path()
Config = ConfigParser.ConfigParser()
if not config_exists():
VerboseLog('Initializing first set up.', ctx)
f = open(config_file, 'w+')
os.makedirs(dot_dir_path())
Config.add_section('options')
VerboseLog('Requesting user options for initial settings.', ctx)
value = click.prompt('GitHub user name', confirmation_prompt=True)
Config.set('options', 'gitname', value)
value = click.prompt('GitHub repo name', default='dotfiles')
Config.set('options', 'reponame', value)
Config.write(f)
f.close()
VerboseLog('Options set.', ctx)
VerboseLog('Cloning repo into $HOME/.dot/', ctx)
git = Git(home(), Conf('options', 'gitname'), Conf('options', 'reponame'))
return_code = git.clone()
VerboseLog('git.clone() return_code was ' + str(return_code), ctx)
if return_code == 0:
click.secho('\ndot is initalized. Run `dot pull` to pull dotfiles,\nor `dot track [dotfile]` if you\'ve never\nused dot. Also see `dot --help`.\n', fg='green')
else:
click.secho('\ndot could not pull your repo from GitHub.\nRun `dot clean` followed by `dot init`\nto start over.\n\n(You may want to check your prerequisites\nat https://github.com/kylefrost/dot-cli#prerequisites.)\n', fg='red')
else:
VerboseLog('Is not initial set up.', ctx)
click.secho('You already set up dot. Run `dot config [option] [value]` to\nchange a config value, or edit ' + config_file + '. To start\nover, run `dot clean`.\n', fg='yellow')
示例7: clone_git_repo
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def clone_git_repo(url, local_path):
git_repo = Git(local_path)
git_repo.clone(url)
示例8: Project
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
class Project():
def __init__(self):
self.tree = ElementTree();
self.git = Git()
if not os.path.exists(PROJECT_CONFIG_PATH):
os.mkdir(PROJECT_CONFIG_PATH)
try:
self.tree.parse(PROJECT_CONFIG_FILE)
except:
root = Element('Project', {'name':os.path.basename(os.getcwd())})
self.tree._setroot(root)
def save(self):
self.tree.write(PROJECT_CONFIG_FILE, xml_declaration=True, method="xml")
def iter(self):
return self.tree.iter('SubProject')
def find(self, name):
for i in self.iter():
if i.get('name') == name:
return i
def inSubProject(self):
cwd = os.getcwd()
for node in self.iter():
name = node.get('name')
print("")
print("On:%s" % name)
print("***************************************")
os.chdir("/".join([cwd, name]))
yield
print("***************************************")
def clone(self):
for module in self.iter():
self.git.clone(module)
def __init_module(self, module):
if not os.path.exists(module):
print("module %s not exists." % module)
return None
cwd = os.getcwd()
os.chdir("/".join([cwd, module]))
if self.git.is_repo():
node = Element('SubProject')
node.set("name", module)
current_branch = self.git.current_branch()
if current_branch != None:
node.set("branch", current_branch)
remote_uri = self.git.current_remote_uri(branch=current_branch)
if remote_uri != None:
node.set("uri", remote_uri)
else:
node = None
else:
print("fatal: Not a git repository")
node = None
os.chdir(cwd)
return node
def __append_ignore_file(self, module):
if os.path.exists(".gitignore"):
ignoreFile = open(".gitignore","r")
for line in ignoreFile:
if module == line.strip():
return
ignoreFile.close()
ignoreFile = open(".gitignore", "a")
ignoreFile.write(module + "\n")
ignoreFile.close()
def __remove_ignore_file(self, modules):
if os.path.exists(".gitignore"):
ignoreFile = open(".gitignore","r")
print modules
data = [line.strip() for line in ignoreFile if not (line.strip() in modules)]
ignoreFile = open(".gitignore", "w")
ignoreFile.write("\n".join(data)+"\n")
ignoreFile.close()
data = None
def append(self, module):
if module == None:
return -1
node = self.find(module)
root = self.tree.getroot()
if node != None:
root.remove(node)
node = self.__init_module(module)
if node == None:
return -1
else:
root.append(node)
self.__append_ignore_file(module)
self.save()
return 0
#.........这里部分代码省略.........
示例9: test_tag
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def test_tag(self):
git = Git(root_dir_local, test_repo_dir)
git.clone()
git.tag(git.latest_commit_id(), "release/1.2.3")
tag_query = lib.call("git describe --abbrev=0 --match release/*")
self.assertEqual(tag_query.stdout.read().strip(), "release/1.2.3")
示例10: test_describe_never_tagged_before
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def test_describe_never_tagged_before(self):
git = Git(root_dir_local, test_repo_dir)
git.clone()
lib.call_and_exit_if_failed("git tag -a release/0.1.1 -m 'releasing version'")
latest_tag = git.describe()
self.assertEqual(latest_tag, "0.1.1")
示例11: test_clone
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clone [as 别名]
def test_clone(self):
git = Git(root_dir_local, test_repo_dir)
git.clone()
self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "README.md")) == 1)