本文整理汇总了Python中datalad.support.gitrepo.GitRepo.get_active_branch方法的典型用法代码示例。如果您正苦于以下问题:Python GitRepo.get_active_branch方法的具体用法?Python GitRepo.get_active_branch怎么用?Python GitRepo.get_active_branch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.get_active_branch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GitRepo_get_merge_base
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_active_branch [as 别名]
def test_GitRepo_get_merge_base(src):
repo = GitRepo(src, create=True)
with open(op.join(src, 'file.txt'), 'w') as f:
f.write('load')
repo.add('*')
repo.commit('committing')
assert_raises(ValueError, repo.get_merge_base, [])
branch1 = repo.get_active_branch()
branch1_hexsha = repo.get_hexsha()
eq_(len(branch1_hexsha), 40)
eq_(repo.get_merge_base(branch1), branch1_hexsha)
# Let's create a detached branch
branch2 = "_detach_"
repo.checkout(branch2, options=["--orphan"])
# it will have all the files
# Must not do: https://github.com/gitpython-developers/GitPython/issues/375
# repo.git_add('.')
repo.add('*')
# NOTE: fun part is that we should have at least a different commit message
# so it results in a different checksum ;)
repo.commit("committing again")
assert(repo.get_indexed_files()) # we did commit
assert(repo.get_merge_base(branch1) is None)
assert(repo.get_merge_base([branch2, branch1]) is None)
# Let's merge them up -- then merge base should match the master
repo.merge(branch1, allow_unrelated=True)
eq_(repo.get_merge_base(branch1), branch1_hexsha)
# if points to some empty/non-existing branch - should also be None
assert(repo.get_merge_base(['nonexistent', branch2]) is None)
示例2: test_fake_dates
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_active_branch [as 别名]
def test_fake_dates(path):
gr = GitRepo(path, create=True, fake_dates=True)
gr.add("foo")
gr.commit("commit foo")
seconds_initial = gr.config.obtain("datalad.fake-dates-start")
# First commit is incremented by 1 second.
eq_(seconds_initial + 1, gr.get_commit_date())
# The second commit by 2.
gr.add("bar")
gr.commit("commit bar")
eq_(seconds_initial + 2, gr.get_commit_date())
# If we checkout another branch, its time is still based on the latest
# timestamp in any local branch.
gr.checkout("other", options=["--orphan"])
with open(op.join(path, "baz"), "w") as ofh:
ofh.write("baz content")
gr.add("baz")
gr.commit("commit baz")
eq_(gr.get_active_branch(), "other")
eq_(seconds_initial + 3, gr.get_commit_date())
示例3: test_GitRepo_ssh_pull
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_active_branch [as 别名]
def test_GitRepo_ssh_pull(remote_path, repo_path):
from datalad import ssh_manager
remote_repo = GitRepo(remote_path, create=True)
url = "ssh://localhost" + op.abspath(remote_path)
socket_path = op.join(ssh_manager.socket_dir, get_connection_hash('localhost'))
repo = GitRepo(repo_path, create=True)
repo.add_remote("ssh-remote", url)
# modify remote:
remote_repo.checkout("ssh-test", ['-b'])
with open(op.join(remote_repo.path, "ssh_testfile.dat"), "w") as f:
f.write("whatever")
remote_repo.add("ssh_testfile.dat")
remote_repo.commit("ssh_testfile.dat added.")
# file is not locally known yet:
assert_not_in("ssh_testfile.dat", repo.get_indexed_files())
# pull changes:
repo.pull(remote="ssh-remote", refspec=remote_repo.get_active_branch())
ok_clean_git(repo.path, annex=False)
# the connection is known to the SSH manager, since fetch() requested it:
assert_in(socket_path, ssh_manager._connections)
# and socket was created:
ok_(op.exists(socket_path))
# we actually pulled the changes
assert_in("ssh_testfile.dat", repo.get_indexed_files())
示例4: test_get_commit_date
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_active_branch [as 别名]
def test_get_commit_date(path):
gr = GitRepo(path, create=True)
eq_(gr.get_commit_date(), None)
# Let's make a commit with a custom date
DATE = "Wed Mar 14 03:47:30 2018 -0000"
DATE_EPOCH = 1520999250
gr.add('1')
gr.commit("committed", date=DATE)
gr = GitRepo(path, create=True)
date = gr.get_commit_date()
neq_(date, None)
eq_(date, DATE_EPOCH)
eq_(date, gr.get_commit_date('master'))
# and even if we get into a detached head
gr.checkout(gr.get_hexsha())
eq_(gr.get_active_branch(), None)
eq_(date, gr.get_commit_date('master'))