本文整理汇总了Python中git.cmd.Git.polish_url方法的典型用法代码示例。如果您正苦于以下问题:Python Git.polish_url方法的具体用法?Python Git.polish_url怎么用?Python Git.polish_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.cmd.Git
的用法示例。
在下文中一共展示了Git.polish_url方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clone
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
if progress is not None:
progress = to_progress_instance(progress)
odbt = kwargs.pop('odbt', odb_default_type)
# when pathlib.Path or other classbased path is passed
if not isinstance(path, str):
path = str(path)
## A bug win cygwin's Git, when `--bare` or `--separate-git-dir`
# it prepends the cwd or(?) the `url` into the `path, so::
# git clone --bare /cygwin/d/foo.git C:\\Work
# becomes::
# git clone --bare /cygwin/d/foo.git /cygwin/d/C:\\Work
#
clone_path = (Git.polish_url(path)
if Git.is_cygwin() and 'bare' in kwargs
else path)
sep_dir = kwargs.get('separate_git_dir')
if sep_dir:
kwargs['separate_git_dir'] = Git.polish_url(sep_dir)
proc = git.clone(Git.polish_url(url), clone_path, with_extended_output=True, as_process=True,
v=True, universal_newlines=True, **add_progress(kwargs, git, progress))
if progress:
handle_process_output(proc, None, progress.new_message_handler(), finalize_process, decode_streams=False)
else:
(stdout, stderr) = proc.communicate()
log.debug("Cmd(%s)'s unused stdout: %s", getattr(proc, 'args', ''), stdout)
finalize_process(proc, stderr=stderr)
# our git command could have a different working dir than our actual
# environment, hence we prepend its working dir if required
if not osp.isabs(path) and git.working_dir:
path = osp.join(git._working_dir, path)
repo = cls(path, odbt=odbt)
# retain env values that were passed to _clone()
repo.git.update_environment(**git.environment())
# adjust remotes - there may be operating systems which use backslashes,
# These might be given as initial paths, but when handling the config file
# that contains the remote from which we were clones, git stops liking it
# as it will escape the backslashes. Hence we undo the escaping just to be
# sure
if repo.remotes:
with repo.remotes[0].config_writer as writer:
writer.set_value('url', Git.polish_url(repo.remotes[0].url))
# END handle remote repo
return repo
示例2: test_diff_with_staged_file
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def test_diff_with_staged_file(self, rw_dir):
# SETUP INDEX WITH MULTIPLE STAGES
r = Repo.init(rw_dir)
fp = osp.join(rw_dir, 'hello.txt')
with open(fp, 'w') as fs:
fs.write("hello world")
r.git.add(Git.polish_url(fp))
r.git.commit(message="init")
with open(fp, 'w') as fs:
fs.write("Hola Mundo")
r.git.commit(all=True, message="change on master")
r.git.checkout('HEAD~1', b='topic')
with open(fp, 'w') as fs:
fs.write("Hallo Welt")
r.git.commit(all=True, message="change on topic branch")
# there must be a merge-conflict
self.failUnlessRaises(GitCommandError, r.git.cherry_pick, 'master')
# Now do the actual testing - this should just work
self.assertEqual(len(r.index.diff(None)), 2)
self.assertEqual(len(r.index.diff(None, create_patch=True)), 0,
"This should work, but doesn't right now ... it's OK")
示例3: test_git_submodules_and_add_sm_with_new_commit
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
parent = git.Repo.init(osp.join(rwdir, 'parent'))
parent.git.submodule('add', self._small_repo_url(), 'module')
parent.index.commit("added submodule")
assert len(parent.submodules) == 1
sm = parent.submodules[0]
assert sm.exists() and sm.module_exists()
clone = git.Repo.clone_from(self._small_repo_url(),
osp.join(parent.working_tree_dir, 'existing-subrepository'))
sm2 = parent.create_submodule('nongit-file-submodule', clone.working_tree_dir)
assert len(parent.submodules) == 2
for _ in range(2):
for init in (False, True):
sm.update(init=init)
sm2.update(init=init)
# end for each init state
# end for each iteration
sm.move(sm.path + '_moved')
sm2.move(sm2.path + '_moved')
parent.index.commit("moved submodules")
with sm.config_writer() as writer:
writer.set_value('user.email', '[email protected]')
writer.set_value('user.name', 'me')
smm = sm.module()
fp = osp.join(smm.working_tree_dir, 'empty-file')
with open(fp, 'w'):
pass
smm.git.add(Git.polish_url(fp))
smm.git.commit(m="new file added")
# submodules are retrieved from the current commit's tree, therefore we can't really get a new submodule
# object pointing to the new submodule commit
sm_too = parent.submodules['module_moved']
assert parent.head.commit.tree[sm.path].binsha == sm.binsha
assert sm_too.binsha == sm.binsha, "cached submodule should point to the same commit as updated one"
added_bies = parent.index.add([sm]) # addded base-index-entries
assert len(added_bies) == 1
parent.index.commit("add same submodule entry")
commit_sm = parent.head.commit.tree[sm.path]
assert commit_sm.binsha == added_bies[0].binsha
assert commit_sm.binsha == sm.binsha
sm_too.binsha = sm_too.module().head.commit.binsha
added_bies = parent.index.add([sm_too])
assert len(added_bies) == 1
parent.index.commit("add new submodule entry")
commit_sm = parent.head.commit.tree[sm.path]
assert commit_sm.binsha == added_bies[0].binsha
assert commit_sm.binsha == sm_too.binsha
assert sm_too.binsha != sm.binsha
示例4: create
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def create(cls, repo, name, url, **kwargs):
"""Create a new remote to the given repository
:param repo: Repository instance that is to receive the new remote
:param name: Desired name of the remote
:param url: URL which corresponds to the remote's name
:param kwargs: Additional arguments to be passed to the git-remote add command
:return: New Remote instance
:raise GitCommandError: in case an origin with that name already exists"""
scmd = 'add'
kwargs['insert_kwargs_after'] = scmd
repo.git.remote(scmd, name, Git.polish_url(url), **kwargs)
return cls(repo, name)
示例5: _do_base_tests
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def _do_base_tests(self, rwrepo):
"""Perform all tests in the given repository, it may be bare or nonbare"""
# manual instantiation
smm = Submodule(rwrepo, "\0" * 20)
# name needs to be set in advance
self.failUnlessRaises(AttributeError, getattr, smm, 'name')
# iterate - 1 submodule
sms = Submodule.list_items(rwrepo, self.k_subm_current)
assert len(sms) == 1
sm = sms[0]
# at a different time, there is None
assert len(Submodule.list_items(rwrepo, self.k_no_subm_tag)) == 0
assert sm.path == 'git/ext/gitdb'
assert sm.path != sm.name # in our case, we have ids there, which don't equal the path
assert sm.url.endswith('github.com/gitpython-developers/gitdb.git')
assert sm.branch_path == 'refs/heads/master' # the default ...
assert sm.branch_name == 'master'
assert sm.parent_commit == rwrepo.head.commit
# size is always 0
assert sm.size == 0
# the module is not checked-out yet
self.failUnlessRaises(InvalidGitRepositoryError, sm.module)
# which is why we can't get the branch either - it points into the module() repository
self.failUnlessRaises(InvalidGitRepositoryError, getattr, sm, 'branch')
# branch_path works, as its just a string
assert isinstance(sm.branch_path, string_types)
# some commits earlier we still have a submodule, but its at a different commit
smold = next(Submodule.iter_items(rwrepo, self.k_subm_changed))
assert smold.binsha != sm.binsha
assert smold != sm # the name changed
# force it to reread its information
del(smold._url)
smold.url == sm.url # @NoEffect
# test config_reader/writer methods
sm.config_reader()
new_smclone_path = None # keep custom paths for later
new_csmclone_path = None #
if rwrepo.bare:
with self.assertRaises(InvalidGitRepositoryError):
with sm.config_writer() as cw:
pass
else:
with sm.config_writer() as writer:
# for faster checkout, set the url to the local path
new_smclone_path = Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path))
writer.set_value('url', new_smclone_path)
writer.release()
assert sm.config_reader().get_value('url') == new_smclone_path
assert sm.url == new_smclone_path
# END handle bare repo
smold.config_reader()
# cannot get a writer on historical submodules
if not rwrepo.bare:
with self.assertRaises(ValueError):
with smold.config_writer():
pass
# END handle bare repo
# make the old into a new - this doesn't work as the name changed
self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_subm_current)
# the sha is properly updated
smold.set_parent_commit(self.k_subm_changed + "~1")
assert smold.binsha != sm.binsha
# raises if the sm didn't exist in new parent - it keeps its
# parent_commit unchanged
self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_no_subm_tag)
# TEST TODO: if a path in the gitmodules file, but not in the index, it raises
# TEST UPDATE
##############
# module retrieval is not always possible
if rwrepo.bare:
self.failUnlessRaises(InvalidGitRepositoryError, sm.module)
self.failUnlessRaises(InvalidGitRepositoryError, sm.remove)
self.failUnlessRaises(InvalidGitRepositoryError, sm.add, rwrepo, 'here', 'there')
else:
# its not checked out in our case
self.failUnlessRaises(InvalidGitRepositoryError, sm.module)
assert not sm.module_exists()
# currently there is only one submodule
assert len(list(rwrepo.iter_submodules())) == 1
assert sm.binsha != "\0" * 20
# TEST ADD
###########
# preliminary tests
# adding existing returns exactly the existing
sma = Submodule.add(rwrepo, sm.name, sm.path)
#.........这里部分代码省略.........
示例6: test_root_module
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
def test_root_module(self, rwrepo):
# Can query everything without problems
rm = RootModule(self.rorepo)
assert rm.module() is self.rorepo
# try attributes
rm.binsha
rm.mode
rm.path
assert rm.name == rm.k_root_name
assert rm.parent_commit == self.rorepo.head.commit
rm.url
rm.branch
assert len(rm.list_items(rm.module())) == 1
rm.config_reader()
with rm.config_writer():
pass
# deep traversal gitdb / async
rsmsp = [sm.path for sm in rm.traverse()]
assert len(rsmsp) >= 2 # gitdb and async [and smmap], async being a child of gitdb
# cannot set the parent commit as root module's path didn't exist
self.failUnlessRaises(ValueError, rm.set_parent_commit, 'HEAD')
# TEST UPDATE
#############
# setup commit which remove existing, add new and modify existing submodules
rm = RootModule(rwrepo)
assert len(rm.children()) == 1
# modify path without modifying the index entry
# ( which is what the move method would do properly )
#==================================================
sm = rm.children()[0]
pp = "path/prefix"
fp = join_path_native(pp, sm.path)
prep = sm.path
assert not sm.module_exists() # was never updated after rwrepo's clone
# assure we clone from a local source
with sm.config_writer() as writer:
writer.set_value('url', Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path)))
# dry-run does nothing
sm.update(recursive=False, dry_run=True, progress=prog)
assert not sm.module_exists()
sm.update(recursive=False)
assert sm.module_exists()
with sm.config_writer() as writer:
writer.set_value('path', fp) # change path to something with prefix AFTER url change
# update fails as list_items in such a situations cannot work, as it cannot
# find the entry at the changed path
self.failUnlessRaises(InvalidGitRepositoryError, rm.update, recursive=False)
# move it properly - doesn't work as it its path currently points to an indexentry
# which doesn't exist ( move it to some path, it doesn't matter here )
self.failUnlessRaises(InvalidGitRepositoryError, sm.move, pp)
# reset the path(cache) to where it was, now it works
sm.path = prep
sm.move(fp, module=False) # leave it at the old location
assert not sm.module_exists()
cpathchange = rwrepo.index.commit("changed sm path") # finally we can commit
# update puts the module into place
rm.update(recursive=False, progress=prog)
sm.set_parent_commit(cpathchange)
assert sm.module_exists()
# add submodule
#================
nsmn = "newsubmodule"
nsmp = "submrepo"
subrepo_url = Git.polish_url(osp.join(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1]))
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=subrepo_url)
csmadded = rwrepo.index.commit("Added submodule").hexsha # make sure we don't keep the repo reference
nsm.set_parent_commit(csmadded)
assert nsm.module_exists()
# in our case, the module should not exist, which happens if we update a parent
# repo and a new submodule comes into life
nsm.remove(configuration=False, module=True)
assert not nsm.module_exists() and nsm.exists()
# dry-run does nothing
rm.update(recursive=False, dry_run=True, progress=prog)
# otherwise it will work
rm.update(recursive=False, progress=prog)
assert nsm.module_exists()
# remove submodule - the previous one
#====================================
sm.set_parent_commit(csmadded)
smp = sm.abspath
assert not sm.remove(module=False).exists()
assert osp.isdir(smp) # module still exists
#.........这里部分代码省略.........
示例7: _do_test_fetch
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import polish_url [as 别名]
#.........这里部分代码省略.........
mkey = "%s/%s" % (remote, 'master')
master_info = res[mkey]
self.assertTrue(master_info.flags & FetchInfo.FORCED_UPDATE)
self.assertIsNotNone(master_info.note)
# normal fast forward - set head back to previous one
rhead.commit = remote_commit
res = fetch_and_test(remote)
self.assertTrue(res[mkey].flags & FetchInfo.FAST_FORWARD)
# new remote branch
new_remote_branch = Head.create(remote_repo, "new_branch")
res = fetch_and_test(remote)
new_branch_info = get_info(res, remote, new_remote_branch)
self.assertTrue(new_branch_info.flags & FetchInfo.NEW_HEAD)
# remote branch rename ( causes creation of a new one locally )
new_remote_branch.rename("other_branch_name")
res = fetch_and_test(remote)
other_branch_info = get_info(res, remote, new_remote_branch)
self.assertEqual(other_branch_info.ref.commit, new_branch_info.ref.commit)
# remove new branch
Head.delete(new_remote_branch.repo, new_remote_branch)
res = fetch_and_test(remote)
# deleted remote will not be fetched
self.failUnlessRaises(IndexError, get_info, res, remote, new_remote_branch)
# prune stale tracking branches
stale_refs = remote.stale_refs
self.assertEqual(len(stale_refs), 2)
self.assertIsInstance(stale_refs[0], RemoteReference)
RemoteReference.delete(rw_repo, *stale_refs)
# test single branch fetch with refspec including target remote
res = fetch_and_test(remote, refspec="master:refs/remotes/%s/master" % remote)
self.assertEqual(len(res), 1)
self.assertTrue(get_info(res, remote, 'master'))
# ... with respec and no target
res = fetch_and_test(remote, refspec='master')
self.assertEqual(len(res), 1)
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
# doing anything. This is new in later binaries
# res = fetch_and_test(remote, refspec=['master', 'fred'])
# self.assertEqual(len(res), 1)
# add new tag reference
rtag = TagReference.create(remote_repo, "1.0-RV_hello.there")
res = fetch_and_test(remote, tags=True)
tinfo = res[str(rtag)]
self.assertIsInstance(tinfo.ref, TagReference)
self.assertEqual(tinfo.ref.commit, rtag.commit)
self.assertTrue(tinfo.flags & tinfo.NEW_TAG)
# adjust tag commit
Reference.set_object(rtag, rhead.commit.parents[0].parents[0])
res = fetch_and_test(remote, tags=True)
tinfo = res[str(rtag)]
self.assertEqual(tinfo.commit, rtag.commit)
self.assertTrue(tinfo.flags & tinfo.TAG_UPDATE)
# delete remote tag - local one will stay
TagReference.delete(remote_repo, rtag)
res = fetch_and_test(remote, tags=True)
self.failUnlessRaises(IndexError, get_info, res, remote, str(rtag))
# provoke to receive actual objects to see what kind of output we have to
# expect. For that we need a remote transport protocol
# Create a new UN-shared repo and fetch into it after we pushed a change
# to the shared repo
other_repo_dir = tempfile.mktemp("other_repo")
# must clone with a local path for the repo implementation not to freak out
# as it wants local paths only ( which I can understand )
other_repo = remote_repo.clone(other_repo_dir, shared=False)
remote_repo_url = osp.basename(remote_repo.git_dir) # git-daemon runs with appropriate `--base-path`.
remote_repo_url = Git.polish_url("git://localhost:%s/%s" % (GIT_DAEMON_PORT, remote_repo_url))
# put origin to git-url
other_origin = other_repo.remotes.origin
with other_origin.config_writer as cw:
cw.set("url", remote_repo_url)
# it automatically creates alternates as remote_repo is shared as well.
# It will use the transport though and ignore alternates when fetching
# assert not other_repo.alternates # this would fail
# assure we are in the right state
rw_repo.head.reset(remote.refs.master, working_tree=True)
try:
self._commit_random_file(rw_repo)
remote.push(rw_repo.head.reference)
# here I would expect to see remote-information about packing
# objects and so on. Unfortunately, this does not happen
# if we are redirecting the output - git explicitly checks for this
# and only provides progress information to ttys
res = fetch_and_test(other_origin)
finally:
rmtree(other_repo_dir)