本文整理汇总了Python中datalad.support.gitrepo.GitRepo.get_branches方法的典型用法代码示例。如果您正苦于以下问题:Python GitRepo.get_branches方法的具体用法?Python GitRepo.get_branches怎么用?Python GitRepo.get_branches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.get_branches方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GitRepo_ssh_push
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_branches [as 别名]
def test_GitRepo_ssh_push(repo_path, remote_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 local repo:
repo.checkout("ssh-test", ['-b'])
with open(op.join(repo.path, "ssh_testfile.dat"), "w") as f:
f.write("whatever")
repo.add("ssh_testfile.dat")
repo.commit("ssh_testfile.dat added.")
# file is not known to the remote yet:
assert_not_in("ssh_testfile.dat", remote_repo.get_indexed_files())
# push changes:
pushed = repo.push(remote="ssh-remote", refspec="ssh-test")
# test PushInfo object for
assert_in("ssh-remote/ssh-test", [commit.remote_ref.name for commit in pushed])
# 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))
# remote now knows the changes:
assert_in("ssh-test", remote_repo.get_branches())
assert_in("ssh_testfile.dat", remote_repo.get_files("ssh-test"))
# amend to make it require "--force":
repo.commit("amended", options=['--amend'])
# push without --force should yield an error:
pushed = repo.push(remote="ssh-remote", refspec="ssh-test")
assert_in("[rejected] (non-fast-forward)", pushed[0].summary)
# now push using force:
repo.push(remote="ssh-remote", refspec="ssh-test", force=True)
# correct commit message in remote:
assert_in("amended",
list(remote_repo.get_branch_commits('ssh-test'))[-1].summary)
示例2: test_GitRepo_remote_update
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_branches [as 别名]
def test_GitRepo_remote_update(path1, path2, path3):
git1 = GitRepo(path1)
git2 = GitRepo(path2)
git3 = GitRepo(path3)
git1.add_remote('git2', path2)
git1.add_remote('git3', path3)
# Setting up remote 'git2'
with open(op.join(path2, 'masterfile'), 'w') as f:
f.write("git2 in master")
git2.add('masterfile')
git2.commit("Add something to master.")
git2.checkout('branch2', ['-b'])
with open(op.join(path2, 'branch2file'), 'w') as f:
f.write("git2 in branch2")
git2.add('branch2file')
git2.commit("Add something to branch2.")
# Setting up remote 'git3'
with open(op.join(path3, 'masterfile'), 'w') as f:
f.write("git3 in master")
git3.add('masterfile')
git3.commit("Add something to master.")
git3.checkout('branch3', ['-b'])
with open(op.join(path3, 'branch3file'), 'w') as f:
f.write("git3 in branch3")
git3.add('branch3file')
git3.commit("Add something to branch3.")
git1.update_remote()
# checkouts are 'tests' themselves, since they'll raise CommandError
# if something went wrong
git1.checkout('branch2')
git1.checkout('branch3')
branches1 = git1.get_branches()
eq_({'branch2', 'branch3'}, set(branches1))
示例3: check_dates
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_branches [as 别名]
def check_dates(repo, timestamp=None, which="newer", revs=None,
annex=True, tags=True):
"""Search for dates in `repo` that are newer than `timestamp`.
This examines commit logs of local branches and the content of blobs in the
git-annex branch.
Parameters
----------
repo : GitRepo or str
If a str is passed, it is taken as the path to a GitRepo.
timestamp : int, optional
Unix timestamp. It defaults to a day before now.
which : {"newer", "older"}
Whether to return timestamps that are newer or older than `timestamp`.
revs : list, optional
Search for commit timestamps in commits that are area reachable from
these revisions. Any revision-specification allowed by `git log` can be
used, including things like `--all`. Defaults to all local branches.
annex : {True, "tree", False}, optional
If True, search the content of all blobs in the git-annex branch. If
"tree", search only the blobs that are in the tree of the tip of the
git-annex branch. If False, do not search git-annex blobs.
tags : bool, optional
Whether to check dates the dates of annotated tags.
Returns
-------
A dict that reports newer timestamps.
"""
if isinstance(repo, string_types):
repo = GitRepo(repo, create=False)
if timestamp is None:
timestamp = int(time.time()) - 60 * 60 * 24
if which == "newer":
cmp_fn = operator.gt
elif which == "older":
cmp_fn = operator.lt
else:
raise ValueError("unrecognized value for `which`: {}".format(which))
results = {}
lgr.debug("Checking dates in logs")
for hexsha, a_timestamp, c_timestamp in log_dates(repo, revs=revs):
if cmp_fn(a_timestamp, timestamp) or cmp_fn(c_timestamp, timestamp):
results[hexsha] = {"type": "commit",
"author-timestamp": a_timestamp,
"committer-timestamp": c_timestamp}
if tags:
lgr.debug("Checking dates of annotated tags")
for hexsha, tag_timestamp in tag_dates(repo):
if cmp_fn(tag_timestamp, timestamp):
results[hexsha] = {"type": "tag",
"timestamp": tag_timestamp}
if annex and "git-annex" in repo.get_branches():
all_objects = annex != "tree"
lgr.debug("Checking dates in blobs of git-annex branch%s",
"" if all_objects else "'s tip")
for hexsha, timestamps, fname in annex_dates(repo, all_objects):
hits = [ts for ts in timestamps if cmp_fn(ts, timestamp)]
if hits:
results[hexsha] = {"type": "annex-blob",
"timestamps": hits,
"filename": fname}
return {"reference-timestamp": timestamp,
"which": which,
"objects": results}