本文整理汇总了Python中datalad.support.gitrepo.GitRepo.commit方法的典型用法代码示例。如果您正苦于以下问题:Python GitRepo.commit方法的具体用法?Python GitRepo.commit怎么用?Python GitRepo.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GitRepo_ssh_pull
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [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())
示例2: test_GitRepo_dirty
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_GitRepo_dirty(path):
repo = GitRepo(path, create=True)
ok_(not repo.dirty)
# untracked file
with open(op.join(path, 'file1.txt'), 'w') as f:
f.write('whatever')
ok_(repo.dirty)
# staged file
repo.add('file1.txt')
ok_(repo.dirty)
# clean again
repo.commit("file1.txt added")
ok_(not repo.dirty)
# modify to be the same
with open(op.join(path, 'file1.txt'), 'w') as f:
f.write('whatever')
ok_(not repo.dirty)
# modified file
with open(op.join(path, 'file1.txt'), 'w') as f:
f.write('something else')
ok_(repo.dirty)
# clean again
repo.add('file1.txt')
repo.commit("file1.txt modified")
ok_(not repo.dirty)
示例3: test_GitRepo__get_files_history
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_GitRepo__get_files_history(path):
gr = GitRepo(path, create=True)
gr.add('d1')
gr.commit("commit d1")
#import pdb; pdb.set_trace()
gr.add(['d2', 'file'])
gr.commit("commit d2")
# commit containing files of d1
d1_commit = next(gr._get_files_history([op.join(path, 'd1', 'f1'), op.join(path, 'd1', 'f1')]))
eq_(str(d1_commit.message), 'commit d1\n')
# commit containing files of d2
d2_commit_gen = gr._get_files_history([op.join(path, 'd2', 'f1'), op.join(path, 'd2', 'f1')])
eq_(str(next(d2_commit_gen).message), 'commit d2\n')
assert_raises(StopIteration, next, d2_commit_gen) # no more commits with files of d2
# union of commits containing passed objects
commits_union = gr._get_files_history([op.join(path, 'd1', 'f1'), op.join(path, 'd2', 'f1'), op.join(path, 'file')])
eq_(str(next(commits_union).message), 'commit d2\n')
eq_(str(next(commits_union).message), 'commit d1\n')
assert_raises(StopIteration, next, commits_union)
# file2 not commited, so shouldn't exist in commit history
no_such_commits = gr._get_files_history([op.join(path, 'file2')])
assert_raises(StopIteration, next, no_such_commits)
示例4: test_optimized_cloning
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_optimized_cloning(path):
# make test repo with one file and one commit
originpath = op.join(path, 'origin')
repo = GitRepo(originpath, create=True)
with open(op.join(originpath, 'test'), 'w') as f:
f.write('some')
repo.add('test')
repo.commit('init')
ok_clean_git(originpath, annex=False)
from glob import glob
def _get_inodes(repo):
return dict(
[(os.path.join(*o.split(os.sep)[-2:]),
os.stat(o).st_ino)
for o in glob(os.path.join(repo.path,
repo.get_git_dir(repo),
'objects', '*', '*'))])
origin_inodes = _get_inodes(repo)
# now clone it in different ways and see what happens to the object storage
from datalad.support.network import get_local_file_url
clonepath = op.join(path, 'clone')
for src in (originpath, get_local_file_url(originpath)):
# deprecated
assert_raises(DeprecatedError, GitRepo, url=src, path=clonepath)
clone = GitRepo.clone(url=src, path=clonepath, create=True)
clone_inodes = _get_inodes(clone)
eq_(origin_inodes, clone_inodes, msg='with src={}'.format(src))
rmtree(clonepath)
示例5: test_GitRepo_gitignore
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_GitRepo_gitignore(path):
gr = GitRepo(path, create=True)
sub = GitRepo(op.join(path, 'ignore-sub.me'))
# we need to commit something, otherwise add_submodule
# will already refuse the submodule for having no commit
sub.add('a_file.txt')
sub.commit()
from ..exceptions import GitIgnoreError
with open(op.join(path, '.gitignore'), "w") as f:
f.write("*.me")
with assert_raises(GitIgnoreError) as cme:
gr.add('ignore.me')
eq_(cme.exception.paths, ['ignore.me'])
with assert_raises(GitIgnoreError) as cme:
gr.add_submodule(path='ignore-sub.me')
eq_(cme.exception.paths, ['ignore-sub.me'])
with assert_raises(GitIgnoreError) as cme:
gr.add(['ignore.me', 'dontigno.re', op.join('ignore-sub.me', 'a_file.txt')])
eq_(set(cme.exception.paths), {'ignore.me', 'ignore-sub.me'})
eq_(gr.get_gitattributes('.')['.'], {}) # nothing is recorded within .gitattributes
示例6: test_get_missing
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_get_missing(path):
repo = GitRepo(path, create=True)
os.makedirs(op.join(path, 'deep'))
with open(op.join(path, 'test1'), 'w') as f:
f.write('some')
with open(op.join(path, 'deep', 'test2'), 'w') as f:
f.write('some more')
# no files tracked yet, so nothing changed
eq_(repo.get_changed_files(), [])
repo.add('.')
# still no differences between worktree and staged
eq_(repo.get_changed_files(), [])
eq_(set(repo.get_changed_files(staged=True)),
{'test1', op.join('deep', 'test2')})
eq_(set(repo.get_changed_files(staged=True, diff_filter='AD')),
{'test1', op.join('deep', 'test2')})
eq_(repo.get_changed_files(staged=True, diff_filter='D'), [])
repo.commit()
eq_(repo.get_changed_files(), [])
eq_(repo.get_changed_files(staged=True), [])
ok_clean_git(path, annex=False)
unlink(op.join(path, 'test1'))
eq_(repo.get_missing_files(), ['test1'])
rmtree(op.join(path, 'deep'))
eq_(sorted(repo.get_missing_files()), [op.join('deep', 'test2'), 'test1'])
# nothing is actually known to be deleted
eq_(repo.get_deleted_files(), [])
# do proper removal
repo.remove(op.join(path, 'test1'))
# no longer missing
eq_(repo.get_missing_files(), [op.join('deep', 'test2')])
# but deleted
eq_(repo.get_deleted_files(), ['test1'])
示例7: test_GitRepo_get_merge_base
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [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)
示例8: test_GitRepo_add_submodule
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_GitRepo_add_submodule(source, path):
top_repo = GitRepo(path, create=True)
top_repo.add_submodule('sub', name='sub', url=source)
top_repo.commit('submodule added')
eq_([s.name for s in top_repo.get_submodules()], ['sub'])
ok_clean_git(path)
ok_clean_git(op.join(path, 'sub'))
示例9: test_GitRepo_remove
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_GitRepo_remove(path):
gr = GitRepo(path, create=True)
gr.add('*')
gr.commit("committing all the files")
eq_(gr.remove('file'), ['file'])
eq_(set(gr.remove('d', r=True, f=True)), {'d/f1', 'd/f2'})
eq_(set(gr.remove('*', r=True, f=True)), {'file2', 'd2/f1', 'd2/f2'})
示例10: test_clone_dataladri
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_clone_dataladri(src, topurl, path):
# make plain git repo
ds_path = opj(src, 'ds')
gr = GitRepo(ds_path, create=True)
gr.add('test.txt')
gr.commit('demo')
Runner(cwd=gr.path)(['git', 'update-server-info'])
# now install it somewhere else
with patch('datalad.consts.DATASETS_TOPURL', topurl):
ds = clone('///ds', path, result_xfm='datasets', return_type='item-or-list')
eq_(ds.path, path)
ok_clean_git(path, annex=False)
ok_file_has_content(opj(path, 'test.txt'), 'some')
示例11: test_install_dataladri
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_install_dataladri(src, topurl, path):
# make plain git repo
ds_path = opj(src, 'ds')
gr = GitRepo(ds_path, create=True)
gr.add('test.txt')
gr.commit('demo')
Runner(cwd=gr.path)(['git', 'update-server-info'])
# now install it somewhere else
with patch('datalad.consts.DATASETS_TOPURL', topurl), \
swallow_logs():
ds = install(path, source='///ds')
eq_(ds.path, path)
ok_clean_git(path, annex=False)
ok_file_has_content(opj(path, 'test.txt'), 'some')
示例12: test_get_commit_date
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [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'))
示例13: test_GitRepo_ssh_push
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [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)
示例14: test_get_tags
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [as 别名]
def test_get_tags(path):
from mock import patch
gr = GitRepo(path, create=True)
eq_(gr.get_tags(), [])
eq_(gr.describe(), None)
# Explicitly override the committer date because tests may set it to a
# fixed value, but we want to check that the returned tags are sorted by
# the committer date.
with patch.dict("os.environ", {"GIT_COMMITTER_DATE":
"Thu, 07 Apr 2005 22:13:13 +0200"}):
create_tree(gr.path, {'file': ""})
gr.add('file')
gr.commit(msg="msg")
eq_(gr.get_tags(), [])
eq_(gr.describe(), None)
gr.tag("nonannotated")
tags1 = [{'name': 'nonannotated', 'hexsha': gr.get_hexsha()}]
eq_(gr.get_tags(), tags1)
eq_(gr.describe(), None)
eq_(gr.describe(tags=True), tags1[0]['name'])
first_commit = gr.get_hexsha()
with patch.dict("os.environ", {"GIT_COMMITTER_DATE":
"Fri, 08 Apr 2005 22:13:13 +0200"}):
create_tree(gr.path, {'file': "123"})
gr.add('file')
gr.commit(msg="changed")
gr.tag("annotated", message="annotation")
tags2 = tags1 + [{'name': 'annotated', 'hexsha': gr.get_hexsha()}]
eq_(gr.get_tags(), tags2)
eq_(gr.describe(), tags2[1]['name'])
# compare prev commit
eq_(gr.describe(commitish=first_commit), None)
eq_(gr.describe(commitish=first_commit, tags=True), tags1[0]['name'])
示例15: test_fake_dates
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import commit [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())