本文整理汇总了Python中pants.scm.git.Git.push方法的典型用法代码示例。如果您正苦于以下问题:Python Git.push方法的具体用法?Python Git.push怎么用?Python Git.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.scm.git.Git
的用法示例。
在下文中一共展示了Git.push方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GitTest
# 需要导入模块: from pants.scm.git import Git [as 别名]
# 或者: from pants.scm.git.Git import push [as 别名]
class GitTest(unittest.TestCase):
@staticmethod
def init_repo(remote_name, remote):
# TODO (peiyu) clean this up, use `git_util.initialize_repo`.
subprocess.check_call(['git', 'init'])
subprocess.check_call(['git', 'config', 'user.email', '[email protected]'])
subprocess.check_call(['git', 'config', 'user.name', 'Your Name'])
subprocess.check_call(['git', 'remote', 'add', remote_name, remote])
def setUp(self):
self.origin = safe_mkdtemp()
with pushd(self.origin):
subprocess.check_call(['git', 'init', '--bare'])
self.gitdir = safe_mkdtemp()
self.worktree = safe_mkdtemp()
self.readme_file = os.path.join(self.worktree, 'README')
with environment_as(GIT_DIR=self.gitdir, GIT_WORK_TREE=self.worktree):
self.init_repo('depot', self.origin)
touch(self.readme_file)
subprocess.check_call(['git', 'add', 'README'])
safe_mkdir(os.path.join(self.worktree, 'dir'))
with open(os.path.join(self.worktree, 'dir', 'f'), 'w') as f:
f.write("file in subdir")
# Make some symlinks
os.symlink('f', os.path.join(self.worktree, 'dir', 'relative-symlink'))
os.symlink('no-such-file', os.path.join(self.worktree, 'dir', 'relative-nonexistent'))
os.symlink('dir/f', os.path.join(self.worktree, 'dir', 'not-absolute\u2764'))
os.symlink('../README', os.path.join(self.worktree, 'dir', 'relative-dotdot'))
os.symlink('dir', os.path.join(self.worktree, 'link-to-dir'))
os.symlink('README/f', os.path.join(self.worktree, 'not-a-dir'))
os.symlink('loop1', os.path.join(self.worktree, 'loop2'))
os.symlink('loop2', os.path.join(self.worktree, 'loop1'))
subprocess.check_call(['git', 'add', 'README', 'dir', 'loop1', 'loop2',
'link-to-dir', 'not-a-dir'])
subprocess.check_call(['git', 'commit', '-am', 'initial commit with decode -> \x81b'])
self.initial_rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
subprocess.check_call(['git', 'tag', 'first'])
subprocess.check_call(['git', 'push', '--tags', 'depot', 'master'])
subprocess.check_call(['git', 'branch', '--set-upstream-to', 'depot/master'])
with safe_open(self.readme_file, 'w') as readme:
readme.write('Hello World.\u2764'.encode('utf-8'))
subprocess.check_call(['git', 'commit', '-am', 'Update README.'])
self.current_rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
self.clone2 = safe_mkdtemp()
with pushd(self.clone2):
self.init_repo('origin', self.origin)
subprocess.check_call(['git', 'pull', '--tags', 'origin', 'master:master'])
with safe_open(os.path.realpath('README'), 'a') as readme:
readme.write('--')
subprocess.check_call(['git', 'commit', '-am', 'Update README 2.'])
subprocess.check_call(['git', 'push', '--tags', 'origin', 'master'])
self.git = Git(gitdir=self.gitdir, worktree=self.worktree)
@contextmanager
def mkremote(self, remote_name):
with temporary_dir() as remote_uri:
subprocess.check_call(['git', 'remote', 'add', remote_name, remote_uri])
try:
yield remote_uri
finally:
subprocess.check_call(['git', 'remote', 'remove', remote_name])
def tearDown(self):
safe_rmtree(self.origin)
safe_rmtree(self.gitdir)
safe_rmtree(self.worktree)
safe_rmtree(self.clone2)
def test_listdir(self):
reader = self.git.repo_reader(self.initial_rev)
for dirname in '.', './.':
results = reader.listdir(dirname)
self.assertEquals(['README',
'dir',
'link-to-dir',
'loop1',
'loop2',
'not-a-dir'],
sorted(results))
for dirname in 'dir', './dir':
results = reader.listdir(dirname)
self.assertEquals(['f',
'not-absolute\u2764'.encode('utf-8'),
'relative-dotdot',
'relative-nonexistent',
'relative-symlink'],
#.........这里部分代码省略.........
示例2: GitTest
# 需要导入模块: from pants.scm.git import Git [as 别名]
# 或者: from pants.scm.git.Git import push [as 别名]
class GitTest(unittest.TestCase):
@staticmethod
def init_repo(remote_name, remote):
subprocess.check_call(['git', 'init'])
subprocess.check_call(['git', 'config', 'user.email', '[email protected]'])
subprocess.check_call(['git', 'config', 'user.name', 'Your Name'])
subprocess.check_call(['git', 'remote', 'add', remote_name, remote])
@classmethod
def setUp(self):
self.origin = safe_mkdtemp()
with pushd(self.origin):
subprocess.check_call(['git', 'init', '--bare'])
self.gitdir = safe_mkdtemp()
self.worktree = safe_mkdtemp()
self.readme_file = os.path.join(self.worktree, 'README')
with environment_as(GIT_DIR=self.gitdir, GIT_WORK_TREE=self.worktree):
self.init_repo('depot', self.origin)
touch(self.readme_file)
subprocess.check_call(['git', 'add', 'README'])
subprocess.check_call(['git', 'commit', '-am', 'initial commit with decode -> \x81b'])
subprocess.check_call(['git', 'tag', 'first'])
subprocess.check_call(['git', 'push', '--tags', 'depot', 'master'])
subprocess.check_call(['git', 'branch', '--set-upstream', 'master', 'depot/master'])
with safe_open(self.readme_file, 'w') as readme:
readme.write('Hello World.')
subprocess.check_call(['git', 'commit', '-am', 'Update README.'])
self.clone2 = safe_mkdtemp()
with pushd(self.clone2):
self.init_repo('origin', self.origin)
subprocess.check_call(['git', 'pull', '--tags', 'origin', 'master:master'])
with safe_open(os.path.realpath('README'), 'a') as readme:
readme.write('--')
subprocess.check_call(['git', 'commit', '-am', 'Update README 2.'])
subprocess.check_call(['git', 'push', '--tags', 'origin', 'master'])
self.git = Git(gitdir=self.gitdir, worktree=self.worktree)
@staticmethod
@contextmanager
def mkremote(remote_name):
with temporary_dir() as remote_uri:
subprocess.check_call(['git', 'remote', 'add', remote_name, remote_uri])
try:
yield remote_uri
finally:
subprocess.check_call(['git', 'remote', 'remove', remote_name])
@classmethod
def tearDown(self):
safe_rmtree(self.origin)
safe_rmtree(self.gitdir)
safe_rmtree(self.worktree)
safe_rmtree(self.clone2)
def test_integration(self):
self.assertEqual(set(), self.git.changed_files())
self.assertEqual(set(['README']), self.git.changed_files(from_commit='HEAD^'))
tip_sha = self.git.commit_id
self.assertTrue(tip_sha)
self.assertTrue(tip_sha in self.git.changelog())
merge_base = self.git.merge_base()
self.assertTrue(merge_base)
self.assertTrue(merge_base in self.git.changelog())
with pytest.raises(Scm.LocalException):
self.git.server_url
with environment_as(GIT_DIR=self.gitdir, GIT_WORK_TREE=self.worktree):
with self.mkremote('origin') as origin_uri:
origin_url = self.git.server_url
self.assertEqual(origin_url, origin_uri)
self.assertTrue(self.git.tag_name.startswith('first-'), msg='un-annotated tags should be found')
self.assertEqual('master', self.git.branch_name)
def edit_readme():
with open(self.readme_file, 'a') as readme:
readme.write('More data.')
edit_readme()
with open(os.path.join(self.worktree, 'INSTALL'), 'w') as untracked:
untracked.write('make install')
self.assertEqual(set(['README']), self.git.changed_files())
self.assertEqual(set(['README', 'INSTALL']), self.git.changed_files(include_untracked=True))
# confirm that files outside of a given relative_to path are ignored
self.assertEqual(set(), self.git.changed_files(relative_to='non-existent'))
#.........这里部分代码省略.........
示例3: GitTest
# 需要导入模块: from pants.scm.git import Git [as 别名]
# 或者: from pants.scm.git.Git import push [as 别名]
class GitTest(unittest.TestCase):
@staticmethod
def init_repo(remote_name, remote):
subprocess.check_call(['git', 'init'])
subprocess.check_call(['git', 'config', 'user.email', '[email protected]'])
subprocess.check_call(['git', 'config', 'user.name', 'Your Name'])
subprocess.check_call(['git', 'remote', 'add', remote_name, remote])
@classmethod
def setUp(self):
self.origin = safe_mkdtemp()
with pushd(self.origin):
subprocess.check_call(['git', 'init', '--bare'])
self.gitdir = safe_mkdtemp()
self.worktree = safe_mkdtemp()
self.readme_file = os.path.join(self.worktree, 'README')
with environment_as(GIT_DIR=self.gitdir, GIT_WORK_TREE=self.worktree):
self.init_repo('depot', self.origin)
touch(self.readme_file)
subprocess.check_call(['git', 'add', 'README'])
subprocess.check_call(['git', 'commit', '-am', 'initial commit with decode -> \x81b'])
subprocess.check_call(['git', 'tag', 'first'])
subprocess.check_call(['git', 'push', '--tags', 'depot', 'master'])
subprocess.check_call(['git', 'branch', '--set-upstream', 'master', 'depot/master'])
with safe_open(self.readme_file, 'w') as readme:
readme.write('Hello World.')
subprocess.check_call(['git', 'commit', '-am', 'Update README.'])
self.clone2 = safe_mkdtemp()
with pushd(self.clone2):
self.init_repo('origin', self.origin)
subprocess.check_call(['git', 'pull', '--tags', 'origin', 'master:master'])
with safe_open(os.path.realpath('README'), 'a') as readme:
readme.write('--')
subprocess.check_call(['git', 'commit', '-am', 'Update README 2.'])
subprocess.check_call(['git', 'push', '--tags', 'origin', 'master'])
self.git = Git(gitdir=self.gitdir, worktree=self.worktree)
@staticmethod
@contextmanager
def mkremote(remote_name):
with temporary_dir() as remote_uri:
subprocess.check_call(['git', 'remote', 'add', remote_name, remote_uri])
try:
yield remote_uri
finally:
subprocess.check_call(['git', 'remote', 'remove', remote_name])
@classmethod
def tearDown(self):
safe_rmtree(self.origin)
safe_rmtree(self.gitdir)
safe_rmtree(self.worktree)
safe_rmtree(self.clone2)
def test_integration(self):
self.assertEqual(set(), self.git.changed_files())
self.assertEqual(set(['README']), self.git.changed_files(from_commit='HEAD^'))
tip_sha = self.git.commit_id
self.assertTrue(tip_sha)
self.assertTrue(tip_sha in self.git.changelog())
merge_base = self.git.merge_base()
self.assertTrue(merge_base)
self.assertTrue(merge_base in self.git.changelog())
with pytest.raises(Scm.LocalException):
self.git.server_url
with environment_as(GIT_DIR=self.gitdir, GIT_WORK_TREE=self.worktree):
with self.mkremote('origin') as origin_uri:
origin_url = self.git.server_url
self.assertEqual(origin_url, origin_uri)
self.assertTrue(self.git.tag_name.startswith('first-'), msg='un-annotated tags should be found')
self.assertEqual('master', self.git.branch_name)
def edit_readme():
with open(self.readme_file, 'a') as readme:
readme.write('More data.')
edit_readme()
with open(os.path.join(self.worktree, 'INSTALL'), 'w') as untracked:
untracked.write('make install')
self.assertEqual(set(['README']), self.git.changed_files())
self.assertEqual(set(['README', 'INSTALL']), self.git.changed_files(include_untracked=True))
# confirm that files outside of a given relative_to path are ignored
self.assertEqual(set(), self.git.changed_files(relative_to='non-existent'))
#.........这里部分代码省略.........