本文整理汇总了Python中git.Repo.init方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.init方法的具体用法?Python Repo.init怎么用?Python Repo.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_file
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_send_file(self):
folder = make_tempdir()
remote = make_tempdir()
filename = join(folder, 'test.txt')
repo = Repo.init(folder)
Repo.init(remote, bare=True)
f = open(filename, 'w')
f.write("1\n2\n7\n5\n6")
f.close()
repo.git.add('.')
repo.git.commit(m="testing")
repo.git.remote('add', 'origin', normpath(remote))
repo.git.push('-u', 'origin', 'master')
fin = make_tempfile("1\n2\n3\n4\n5\n6")
json = send(
norm_path(filename),
2,
5,
norm_path(fin),
True,
norm_path(folder)
)
self.assertNotEqual(json, False)
payload = loads(json)
self.assertEqual(payload['lines[]'], [2, 4])
delete_tempfolder(folder)
delete_tempfolder(remote)
示例2: main
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def main(argv):
StartDirectory = 'C:\\Projekte\\windekis_src\\'
if len(argv) > 0:
StartDirectory = argv[0]
print(config_root)
if os.path.exists(os.path.join(config_root,'.git')):
print('Update repo git_templates_cim')
repo = Repo(config_root)
o = repo.remotes.origin
o.pull('--rebase')
else:
print('Clone repo git_templates_cim')
os.makedirs(config_root)
Repo.clone_from('[email protected]:git_templates_cim', config_root)
template_dir = os.getenv('GIT_TEMPLATE_DIR', 'EMPTY')
if template_dir != config_root:
print('Temporarily set environment variable GIT_TEMPLATE_DIR to',config_root)
os.environ['GIT_TEMPLATE_DIR'] = config_root
for dirname, dirnames, filenames in os.walk(StartDirectory):
# print path to all filenames.
for dir in dirnames:
if dir == 'hooks':
parent_dir = os.path.abspath(os.path.join(dirname, dir, os.pardir))
if os.path.split(parent_dir)[1] == '.git':
hook_dir = os.path.join(dirname, 'hooks')
hook_bak = add_unique_postfix(hook_dir + '_bak')
print('Backup hooks')
shutil.move(hook_dir,hook_bak)
repo_dir = os.path.abspath(os.path.join(dirname, os.pardir))
print('Reset hooks in repo: ', repo_dir)
Repo.init(repo_dir)
示例3: git_create_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def git_create_repo(url, repo_path, remote, ref, depth=0):
"""Clone git repo from url at path"""
if not os.path.isdir(os.path.join(repo_path, '.git')):
if not os.path.isdir(repo_path):
os.makedirs(repo_path)
repo_path_output = colored(repo_path, 'cyan')
try:
print(' - Clone repo at ' + repo_path_output)
Repo.init(repo_path)
except:
cprint(' - Failed to initialize repository', 'red')
print('')
shutil.rmtree(repo_path)
sys.exit(1)
else:
repo = _repo(repo_path)
remote_names = [r.name for r in repo.remotes]
remote_output = colored(remote, 'yellow')
if remote not in remote_names:
try:
print(" - Create remote " + remote_output)
repo.create_remote(remote, url)
except:
message = colored(" - Failed to create remote ", 'red')
print(message + remote_output)
print('')
shutil.rmtree(repo_path)
sys.exit(1)
_checkout_ref(repo_path, ref, remote, depth)
示例4: init
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def init(rid):
"""
Initialize a new repository.
"""
directory = os.path.join(settings.REPO_DIR, str(rid))
Repo.init(directory)
return PasteRepo(rid)
示例5: init
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def init(path=None):
"""Creates an empty uj project. If possible and not existing, it initializes a git repository."""
# Initialize current directory if no arguments where given.
target_directory = path or "./"
# Walk through empty source directory and copy any non existing files.
for (dir_path, dir_names, file_names) in os.walk(empty_project_dir):
# Get relative path to source root.
rel_path = os.path.relpath(dir_path, empty_project_dir)
# Get path to current target directory
target_path = os.path.normpath(os.path.join(target_directory, rel_path))
# Create target directory if necessary.
if not os.path.isdir(target_path):
os.mkdir(target_path)
# Create file id necessary.
for file_name in file_names:
if not os.path.exists(os.path.join(target_path, file_name)):
copyfile(os.path.join(dir_path, file_name), os.path.join(target_path, file_name))
# If it's copying a ujml file. Fill is the version number.
if file_name.endswith(".ujml"):
with open(os.path.join(target_path, file_name), "r") as f:
content = f.read()
with open(os.path.join(target_path, file_name), "w") as f:
f.write(content.format(version=uj_version))
# If possible make sure it's a git repository.
if git_available:
try:
Repo(target_directory)
except InvalidGitRepositoryError:
Repo.init(target_directory)
示例6: addproj
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def addproj(request):
if request.method=='POST':
from django.conf import settings
repo=os.path.join(settings.REPOS,request.POST['pname'])
commits=os.path.join(settings.COMMITS,request.POST['pname'])
config=os.path.join(settings.USERS,request.POST['pname'])
if os.path.exists(repo):
return HttpResponseRedirect('/home?message=Project Already Exists!!')
else:
from git import Repo
try:
User.objects.create_user(request.POST['pname'],'','')
os.mkdir(repo)
os.mkdir(commits)
f=open(config,'a')
f.write('active\n')
f.close()
except OSError,IntegrityError:
return HttpResponseRedirect('/home?message=Project Already Exists!!')
Repo.init(repo)
os.mkdir(os.path.join(repo,request.POST['pname']))
target=os.path.join(settings.COMMITS,request.POST['pname']+'/head')
f=open(target,'a')
f.write('Initial commit\n')
f.close()
return HttpResponseRedirect('/a/user/add?message=Project Created!!')
示例7: test_init
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_init(self):
prev_cwd = os.getcwd()
os.chdir(tempfile.gettempdir())
git_dir_rela = "repos/foo/bar.git"
del_dir_abs = os.path.abspath("repos")
git_dir_abs = os.path.abspath(git_dir_rela)
try:
# with specific path
for path in (git_dir_rela, git_dir_abs):
r = Repo.init(path=path, bare=True)
assert isinstance(r, Repo)
assert r.bare is True
assert not r.has_separate_working_tree()
assert os.path.isdir(r.git_dir)
self._assert_empty_repo(r)
# test clone
clone_path = path + "_clone"
rc = r.clone(clone_path)
self._assert_empty_repo(rc)
try:
shutil.rmtree(clone_path)
except OSError:
# when relative paths are used, the clone may actually be inside
# of the parent directory
pass
# END exception handling
# try again, this time with the absolute version
rc = Repo.clone_from(r.git_dir, clone_path)
self._assert_empty_repo(rc)
shutil.rmtree(git_dir_abs)
try:
shutil.rmtree(clone_path)
except OSError:
# when relative paths are used, the clone may actually be inside
# of the parent directory
pass
# END exception handling
# END for each path
os.makedirs(git_dir_rela)
os.chdir(git_dir_rela)
r = Repo.init(bare=False)
assert r.bare is False
assert not r.has_separate_working_tree()
self._assert_empty_repo(r)
finally:
try:
shutil.rmtree(del_dir_abs)
except OSError:
pass
os.chdir(prev_cwd)
示例8: main_add
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def main_add(self, repo, rc=0, args={}):
os.mkdir(os.path.join(self.tempdir.name, repo.split('/')[-1]))
Repo.init(os.path.join(self.tempdir.name, repo.split('/')[-1]))
assert rc == main(self.setup_args({
'add': True,
'<user>/<repo>': repo,
'--path': self.tempdir.name
}, args)), "Non {} result for add".format(rc)
return RepositoryService._current._did_add
示例9: configure_remote
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def configure_remote(self, remote):
if remote is None:
return
if self.check_property('disable_%s' % remote.status):
return
if self.check_property('super') and remote.status == 'upstream':
return
try:
repo = NamedRepo(remote.name, remote.name)
except:
Repo.init(remote.name)
repo = NamedRepo(remote.name, remote.name)
try:
gitremote = repo.remotes.origin
except:
gitremote = repo.create_remote('origin', remote.url)
logging.debug('Creating remote for %s' % remote.name)
if gitremote.url != remote.url:
cw = gitremote.config_writer
cw.set("url", remote.url)
logging.debug('Changing remote url for %s' % remote.name)
cw.release()
#repo.delete_head('master')
if not remote.parent.check_property('disable_update'):
logging.debug('Fetching remote for %s...' % remote.name)
gitremote.fetch()
if remote.parent.check_property('super'):
logging.debug('Running git submodules sync')
repo.git.submodule('sync')
logging.debug('Fetching remote for %s. done.' % remote.name)
if not remote.branch in gitremote.refs:
logging.error('Can not find %s branch in %s' % (remote.branch, remote.name))
exit(1)
if not 'master' in repo.heads:
branch = repo.create_head('master', gitremote.refs[remote.branch]).set_tracking_branch(gitremote.refs[remote.branch])
else:
branch = repo.heads['master']
branch.set_tracking_branch(gitremote.refs[remote.branch])
repo.head.set_reference(branch)
repo.head.reset(gitremote.refs[remote.branch].commit, index=True, working_tree=True)
if remote.parent.check_property('super'):
for sm in repo.submodules:
self.runtime.submodules_urls.add(normalizegiturl(sm.url))
if not remote.parent.check_property('disable_update'):
try:
if sm.hexsha != sm.module().commit().hexsha:
logging.debug('Updating %s...' % sm.path)
sm.update(force=True, recursive=False)
else:
logging.debug('%s is up to date at %s...' % (sm.path, sm.hexsha))
except InvalidGitRepositoryError:
logging.debug('Fetching %s...' % sm.path)
sm.update(force=True, recursive=False)
示例10: main_delete
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def main_delete(self, repo=None, rc=0, args={}):
if repo:
repo_path = os.path.join(self.tempdir.name, repo.split('/')[-1])
os.mkdir(repo_path)
Repo.init(repo_path)
assert rc == main(self.setup_args({
'delete': True,
'<user>/<repo>': repo,
'--path': self.tempdir.name,
}, args)), "Non {} result for delete".format(rc)
return RepositoryService._current._did_delete
示例11: test_tilde_and_env_vars_in_repo_path
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_tilde_and_env_vars_in_repo_path(self, rw_dir):
ph = os.environ['HOME']
try:
os.environ['HOME'] = rw_dir
Repo.init(os.path.join('~', 'test.git'), bare=True)
os.environ['FOO'] = rw_dir
Repo.init(os.path.join('$FOO', 'test.git'), bare=True)
finally:
os.environ['HOME'] = ph
del os.environ['FOO']
示例12: setUp
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def setUp(self):
super().setUp()
self.clean_workspace()
self.repo = Repo.init(self.get_path())
self.remote_repo = Repo.init(self.get_path() + '_remote', bare=True)
self.repo.create_remote(DEFAULT_REMOTE, self.remote_repo.working_dir)
self.commit_new_file('test.txt', 'test data')
self.repo.git.checkout('-b', 'develop')
self.repo.remote().push(self.repo.active_branch.name)
self.repo.git.checkout('master')
self.uri = '[email protected]:test/{}.git'.format(REPO_NAME)
self.repo_manager = RepoManager(REPO_NAME, self.uri, WORKSPACE)
示例13: moz_env
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def moz_env(post_db_setup, _django_cursor_wrapper, ios_pootle_file):
from django.conf import settings
from pytest_pootle.factories import (
ProjectDBFactory, StoreDBFactory,
TranslationProjectFactory)
from pootle_fs.models import ProjectFS
from pootle_language.models import Language
with _django_cursor_wrapper:
ios_project = ProjectDBFactory(
source_language=Language.objects.get(code="en"),
code="ios",
localfiletype="xliff")
ios_tp = TranslationProjectFactory(
project=ios_project,
language=Language.objects.get(code="language0"))
ios_store = StoreDBFactory(
parent=ios_tp.directory,
translation_project=ios_tp,
name="firefox-ios.xliff")
ios_bytes = io.BytesIO(ios_pootle_file.encode("utf8"))
ios_store.update(
getclass(ios_bytes)(ios_bytes.read()))
fs_dir = tempfile.mkdtemp()
settings.POOTLE_FS_PATH = fs_dir
repo_path = os.path.join(fs_dir, "__moz_ios_src__")
Repo.init(repo_path, bare=True)
with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
config_file = os.path.join(tmp_repo_path, ".pootle.ini")
with open(config_file, "w") as ini:
config = (
"[default]\n"
"serializers = ios\n"
"deserializers = ios\n"
"translation_path = <lang>/<filename>.xliff")
ini.write(config)
tmp_repo.index.add([".pootle.ini"])
tmp_repo.index.commit("Add Pootle configuration")
tmp_repo.remotes.origin.push("master:master")
ios_fs = ProjectFS.objects.create(
project=ios_project,
fs_type="git",
url=repo_path)
ios_plugin = ios_fs.plugin
ios_plugin.add_translations()
示例14: git_clone_url_at_path
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def git_clone_url_at_path(url, repo_path, ref, remote):
"""Clone git repo from url at path"""
repo_path_output = colored(repo_path, 'cyan')
if not os.path.isdir(os.path.join(repo_path, '.git')):
if not os.path.isdir(repo_path):
os.makedirs(repo_path)
try:
print(' - Cloning repo at ' + repo_path_output)
Repo.init(repo_path)
except:
cprint(' - Failed to initialize repository', 'red')
else:
git_create_remote(repo_path, remote, url)
git_fetch(repo_path)
git_checkout_ref(repo_path, ref, remote)
示例15: createProject
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def createProject(self, projectName):
projectId = projectName.replace(" ", "-")
full_path = os.path.join(self.__config.GIT_REPO_DIRECTORY, projectId)
if os.path.exists(full_path):
raise Exception("Project path already exist")
os.mkdir(full_path)
Repo.init(full_path, bare=True)
project = Project(self.__config, projectId)
self.__initializeRepo(project, projectName)
return project