本文整理汇总了Python中vcstools.GitClient.checkout方法的典型用法代码示例。如果您正苦于以下问题:Python GitClient.checkout方法的具体用法?Python GitClient.checkout怎么用?Python GitClient.checkout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcstools.GitClient
的用法示例。
在下文中一共展示了GitClient.checkout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def setUpClass(self):
GitClientTestSetups.setUpClass()
client = GitClient(self.local_path)
client.checkout(self.remote_path, self.readonly_version)
self.basepath_export = os.path.join(self.root_directory, 'export')
示例2: test_get_current_version_label
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_get_current_version_label(self):
client = GitClient(path=self.local_path)
# with detached local status
client.checkout(url=self.remote_path, version='test_tag')
self.assertEqual(client.get_current_version_label(), '<detached>')
# when difference between local and tracking branch
client.update(version='master')
self.assertEqual(client.get_current_version_label(), 'master')
# with other tracking branch
cmd = 'git config --replace-all branch.master.merge test_branch'
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
self.assertEqual(client.get_current_version_label(),
'master < test_branch')
# with other remote
for cmd in [
'git remote add remote2 %s' % self.remote_path,
'git config --replace-all branch.master.remote remote2',
'git fetch remote2']:
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
self.assertEqual(client.get_current_version_label(),
'master < remote2/test_branch')
# return remote back to original config
for cmd in [
'git config --replace-all branch.master.remote origin',
'git config --replace-all branch.master.merge refs/heads/master']:
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
示例3: test_get_branch_parent
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_get_branch_parent(self):
client = GitClient(path=self.local_path)
client.checkout(url=self.remote_path, version='master')
self.assertEqual(client._get_branch_parent(), ("master", "origin"))
# with other remote than origin
for cmd in ['git remote add remote2 %s' % self.remote_path,
'git config --replace-all branch.master.remote remote2']:
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
self.assertEqual(client._get_branch_parent(), (None, None))
self.assertEqual(client._get_branch_parent(fetch=True), ('master', "remote2"))
# with not actual remote branch
cmd = 'git config --replace-all branch.master.merge dummy_branch'
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
self.assertEqual(client._get_branch_parent(), (None, None))
# return remote back to original config
for cmd in [
'git config --replace-all branch.master.remote origin',
'git config --replace-all branch.master.merge refs/heads/master']:
subprocess.check_call(cmd, shell=True, cwd=self.local_path)
# with detached local status
client.update(version='test_tag')
self.assertEqual(client._get_branch_parent(), (None, None))
# back to master branch
client.update(version='master')
示例4: setUp
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def setUp(self):
client = GitClient(self.local_path)
client.checkout(self.remote_path)
# Create some local untracking branch
subprocess.check_call("git checkout test_tag -b localbranch", shell=True, cwd=self.local_path)
subprocess.check_call("touch local.txt", shell=True, cwd=self.local_path)
subprocess.check_call("git add *", shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m my_branch", shell=True, cwd=self.local_path)
subprocess.check_call("git tag my_branch_tag", shell=True, cwd=self.local_path)
po = subprocess.Popen("git log -n 1 --pretty=format:\"%H\"", shell=True, cwd=self.local_path, stdout=subprocess.PIPE)
self.untracked_version = po.stdout.read().decode('UTF-8').rstrip('"').lstrip('"')
# Go detached to create some dangling commits
subprocess.check_call("git checkout test_tag", shell=True, cwd=self.local_path)
# create a commit only referenced by tag
subprocess.check_call("touch tagged.txt", shell=True, cwd=self.local_path)
subprocess.check_call("git add *", shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m no_branch", shell=True, cwd=self.local_path)
subprocess.check_call("git tag no_br_tag", shell=True, cwd=self.local_path)
# create a dangling commit
subprocess.check_call("touch dangling.txt", shell=True, cwd=self.local_path)
subprocess.check_call("git add *", shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m dangling", shell=True, cwd=self.local_path)
po = subprocess.Popen("git log -n 1 --pretty=format:\"%H\"", shell=True, cwd=self.local_path, stdout=subprocess.PIPE)
self.dangling_version = po.stdout.read().decode('UTF-8').rstrip('"').lstrip('"')
# go back to master to make head point somewhere else
subprocess.check_call("git checkout master", shell=True, cwd=self.local_path)
示例5: test_checkout_dir_exists
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_checkout_dir_exists(self):
url = self.remote_path
client = GitClient(self.local_path)
self.assertFalse(client.path_exists())
os.makedirs(self.local_path)
self.assertTrue(client.checkout(url))
# non-empty
self.assertFalse(client.checkout(url))
示例6: setUp
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def setUp(self):
client = GitClient(self.local_path)
client.checkout(self.remote_path)
# Create some local untracking branch
subprocess.check_call("git checkout test_tag -b localbranch", shell=True, cwd=self.local_path)
subprocess.check_call("touch local_file", shell=True, cwd=self.local_path)
subprocess.check_call("git add local_file", shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m \"local_file\"", shell=True, cwd=self.local_path)
示例7: setUp
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def setUp(self):
client = GitClient(self.local_path)
client.checkout(self.remote_path)
# Create some local untracking branch
subprocess.check_call("git checkout test_tag -b localbranch", shell=True, cwd=self.local_path)
self.n_commits = 10
for i in range(self.n_commits):
subprocess.check_call("touch local_%d.txt" % i, shell=True, cwd=self.local_path)
subprocess.check_call("git add local_%d.txt" % i, shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m \"local_%d\"" % i, shell=True, cwd=self.local_path)
示例8: testGetBranches
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def testGetBranches(self):
client = GitClient(self.local_path)
client.checkout(self.remote_path)
self.assertEqual(client.get_branches(True), ['master'])
self.assertEqual(client.get_branches(),
['master', 'remotes/origin/master',
'remotes/origin/test_branch'])
subprocess.check_call('git checkout test_branch', shell=True,
cwd=self.local_path, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(client.get_branches(True), ['master', 'test_branch'])
self.assertEqual(client.get_branches(),
['master', 'test_branch', 'remotes/origin/master',
'remotes/origin/test_branch'])
示例9: test_get_default_remote_version_label
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_get_default_remote_version_label(self):
url = self.remote_path
client = GitClient(self.local_path)
self.assertTrue(client.checkout(url))
self.assertEqual(client.get_default_remote_version_label(), 'master')
subprocess.check_call("git symbolic-ref HEAD refs/heads/test_branch", shell=True, cwd=self.remote_path)
self.assertEqual(client.get_default_remote_version_label(), 'test_branch')
示例10: test_checkout_specific_branch_and_update
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_checkout_specific_branch_and_update(self):
# subdir = "checkout_specific_version_test"
url = self.remote_path
branch = "test_branch"
client = GitClient(self.local_path)
self.assertFalse(client.path_exists())
self.assertFalse(client.detect_presence())
self.assertTrue(client.checkout(url, branch))
self.assertTrue(client.path_exists())
self.assertTrue(client.detect_presence())
self.assertTrue(client._is_local_branch(branch))
self.assertEqual(client.get_path(), self.local_path)
self.assertEqual(client.get_url(), url)
self.assertEqual(client.get_version(), self.readonly_version_init)
self.assertEqual(client._get_branch(), branch)
self.assertEqual(client._get_branch_parent(), (branch, "origin"))
self.assertTrue(client.update()) # no arg
self.assertEqual(client._get_branch(), branch)
self.assertEqual(client.get_version(), self.readonly_version_init)
self.assertEqual(client._get_branch_parent(), (branch, "origin"))
self.assertTrue(client.update(branch)) # same branch arg
self.assertEqual(client._get_branch(), branch)
self.assertEqual(client.get_version(), self.readonly_version_init)
self.assertEqual(client._get_branch_parent(), (branch, "origin"))
new_branch = 'master'
self.assertTrue(client.update(new_branch))
self.assertEqual(client._get_branch(), new_branch)
self.assertEqual(client._get_branch_parent(), (new_branch, "origin"))
示例11: test_checkout_no_unnecessary_updates_other_branch
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_checkout_no_unnecessary_updates_other_branch(self):
client = GitClient(self.local_path)
client.fetches = 0
client.submodules = 0
client.fast_forwards = 0
def ifetch(self):
self.fetches += 1
return True
def iff(self, branch_parent, fetch=True, verbose=False):
self.fast_forwards += 1
return True
def isubm(self, verbose=False, timeout=None):
self.submodules += 1
return True
client._do_fetch = types.MethodType(ifetch, client)
client._do_fast_forward = types.MethodType(iff, client)
client._update_submodules = types.MethodType(isubm, client)
url = self.remote_path
self.assertFalse(client.path_exists())
self.assertFalse(client.detect_presence())
self.assertTrue(client.checkout(url, 'test_branch'))
self.assertEqual(1, client.submodules)
self.assertEqual(0, client.fetches)
self.assertEqual(0, client.fast_forwards)
示例12: test_fast_forward_simple_ref
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_fast_forward_simple_ref(self):
url = self.remote_path
client = GitClient(self.local_path)
self.assertTrue(client.checkout(url, "master"))
subprocess.check_call("git reset --hard test_tag", shell=True, cwd=self.local_path)
# replace "refs/head/master" with just "master"
subprocess.check_call("git config --replace-all branch.master.merge master", shell=True, cwd=self.local_path)
self.assertTrue(client._get_branch_parent() is not (None, None))
示例13: test_fast_forward_diverged
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_fast_forward_diverged(self):
url = self.remote_path
client = GitClient(self.local_path)
self.assertTrue(client.checkout(url, "master"))
subprocess.check_call("git reset --hard test_tag", shell=True, cwd=self.local_path)
subprocess.check_call("touch diverged.txt", shell=True, cwd=self.local_path)
subprocess.check_call("git add *", shell=True, cwd=self.local_path)
subprocess.check_call("git commit -m diverge", shell=True, cwd=self.local_path)
# fail because we have diverged
self.assertFalse(client.update('master'))
示例14: test_checkout
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_checkout(self):
url = self.remote_path
client = GitClient(self.local_path)
self.assertFalse(client.path_exists())
self.assertFalse(client.detect_presence())
self.assertTrue(client.checkout(url))
self.assertTrue(client.path_exists())
self.assertTrue(client.detect_presence())
self.assertEqual(client.get_path(), self.local_path)
self.assertEqual(client.get_url(), url)
self.assertEqual(client._get_branch(), "master")
self.assertEqual(client._get_branch_parent(), ("master", "origin"))
示例15: test_checkout_timeout
# 需要导入模块: from vcstools import GitClient [as 别名]
# 或者: from vcstools.GitClient import checkout [as 别名]
def test_checkout_timeout(self):
## SSH'ing to a mute server will hang for a very long time
url = 'ssh://[email protected]:{0}/test'.format(self.mute_port)
client = GitClient(self.local_path)
start = time.time()
self.assertFalse(client.checkout(url, timeout=2.0))
stop = time.time()
self.assertTrue(stop - start > 1.9)
self.assertTrue(stop - start < 3.0)
# the git processes will clean up the checkout dir, we have to wait
# for them to finish in order to avoid a race condition with rmtree()
while os.path.exists(self.local_path):
time.sleep(0.2)