本文整理汇总了Python中repoman.git.repository.Repository.add方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.add方法的具体用法?Python Repository.add怎么用?Python Repository.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repoman.git.repository.Repository
的用法示例。
在下文中一共展示了Repository.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_files
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_add_files(self):
file_name = "absurd_file"
file_path = os.path.join(self.main_repo, file_name)
file_name2 = "absurd_file2"
file_path2 = os.path.join(self.main_repo, file_name2)
with open(file_path, "w") as file:
file_content = "Absurd content"
file.write(file_content)
with open(file_path2, "w") as file:
file_content = "Absurd content2"
file.write(file_content)
repo = pygit2.Repository(self.main_repo)
status = repo.status()
self.assertTrue(file_name in status)
self.assertTrue(file_name2 in status)
self.assertEquals(status[file_name], pygit2.GIT_STATUS_WT_NEW)
self.assertEquals(status[file_name2], pygit2.GIT_STATUS_WT_NEW)
gitrepo = Repository(self.main_repo)
gitrepo.add([file_name, file_name2])
status = repo.status()
self.assertEquals(status[file_name], pygit2.GIT_STATUS_INDEX_NEW)
self.assertEquals(status[file_name2], pygit2.GIT_STATUS_INDEX_NEW)
with self.assertRaises(RepositoryError):
gitrepo.add("nonexistentfile")
示例2: test_add_files
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_add_files(self):
file_name = "absurd_file"
file_path = os.path.join(self.main_repo, file_name)
file_name2 = "absurd_file2"
file_path2 = os.path.join(self.main_repo, file_name2)
with open(file_path, "w") as file:
file_content = "Absurd content"
file.write(file_content)
with open(file_path2, "w") as file:
file_content = "Absurd content2"
file.write(file_content)
def get_status():
git = GitCmd(self.main_repo)
status = {}
for f in git('status', porcelain=True, _iter=True):
s, path = f.split()
status[path] = s
return status
status = get_status()
self.assertTrue(file_name in status)
self.assertTrue(file_name2 in status)
self.assertEquals(status[file_name], '??')
self.assertEquals(status[file_name2], '??')
gitrepo = Repository(self.main_repo)
gitrepo.add([file_name, file_name2])
status = get_status()
self.assertEquals(status[file_name], 'A')
self.assertEquals(status[file_name2], 'A')
with self.assertRaises(RepositoryError):
gitrepo.add("nonexistentfile")
示例3: test_merge_with_conflict
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_merge_with_conflict(self):
gitrepo = Repository(self.cloned_from_repo)
# Checkout
gitrepo.update('newbranch')
file_to_conflict_name = 'test1.txt'
file_to_conflict = os.path.join(self.cloned_from_repo,
file_to_conflict_name)
with open(file_to_conflict, "w") as file:
file_content = "Absurd content"
file.write(file_content)
gitrepo.add(file_to_conflict_name)
conflict_cs = gitrepo.commit("Provoking conflict")
gitrepo.update('master')
try:
gitrepo.merge(other_rev=conflict_cs)
self.fail()
except MergeConflictError as exp:
self.assertTrue('Conflicts found: merging test1.txt failed' in exp)
示例4: test_merge_fastforward_no_ff
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_merge_fastforward_no_ff(self):
repo = pygit2.Repository(self.cloned_from_repo)
gitrepo = Repository(self.cloned_from_repo)
gitrepo.update('master')
gitrepo.branch('ff-branch')
ff_file_name = 'ff-file.txt'
ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
with open(ff_file, "w") as file:
file_content = "Absurd content"
file.write(file_content)
gitrepo.add(ff_file_name)
ff_head = gitrepo.commit(message="commit ff file")
gitrepo.update('master')
cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test')
self.assertEquals(len(repo.head.get_object().parents), 2)
self.assertEquals(repo.head.get_object().hex, cs.hash)
# We want a commit in fastforward merges, hashes must be different
self.assertNotEquals(ff_head.hash, cs.hash)
self.assertTrue(os.path.isfile(ff_file))
示例5: test_merge_fastforward_no_ff
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_merge_fastforward_no_ff(self):
git = GitCmd(self.cloned_from_repo)
gitrepo = Repository(self.cloned_from_repo)
gitrepo.update('master')
gitrepo.branch('ff-branch')
ff_file_name = 'ff-file.txt'
ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
with open(ff_file, "w") as file:
file_content = "Absurd content"
file.write(file_content)
gitrepo.add(ff_file_name)
ff_head = gitrepo.commit(message="commit ff file")
gitrepo.update('master')
cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test')
self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2)
self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
# We want a commit in fastforward merges, hashes must be different
self.assertNotEquals(ff_head.hash, cs.hash)
self.assertTrue(os.path.isfile(ff_file))
示例6: test_commit
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_commit(self):
file_name = "test_file"
file_path = os.path.join(self.main_repo, file_name)
with open(file_path, "a") as file:
file.write('test content')
commit_msg = "Test message"
git = GitCmd(self.main_repo)
initial_len = len(list(git('log', 'HEAD', pretty='oneline', _iter=True)))
gitrepo = Repository(self.main_repo)
gitrepo.add(file_name)
commit = gitrepo.commit(commit_msg)
final_len = len(list(git('log', 'HEAD', pretty='oneline', _iter=True)))
self.assertEquals(final_len, initial_len + 1)
self.assertEquals(git('log', '-1', pretty='%B'), commit_msg)
self.assertEquals(commit.desc, commit_msg)
self.assertIsNone(gitrepo.commit(commit_msg))
示例7: test_commit
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_commit(self):
file_name = "test_file"
file_path = os.path.join(self.main_repo, file_name)
with open(file_path, "a") as file:
file.write('test content')
commit_msg = "Test message"
repo = pygit2.Repository(self.main_repo)
initial_len = len(list(repo.walk(repo.head.target,
pygit2.GIT_SORT_TOPOLOGICAL)))
gitrepo = Repository(self.main_repo)
gitrepo.add(file_name)
commit = gitrepo.commit(commit_msg)
final_len = len(list(repo.walk(repo.head.target,
pygit2.GIT_SORT_TOPOLOGICAL)))
self.assertEquals(final_len, initial_len + 1)
self.assertEquals(repo.head.get_object().message, commit_msg)
self.assertEquals(commit.desc, commit_msg)
self.assertIsNone(gitrepo.commit(commit_msg))
示例8: test_merge_fastforward
# 需要导入模块: from repoman.git.repository import Repository [as 别名]
# 或者: from repoman.git.repository.Repository import add [as 别名]
def test_merge_fastforward(self):
repo = pygit2.Repository(self.cloned_from_repo)
gitrepo = Repository(self.cloned_from_repo)
gitrepo.update('master')
gitrepo.branch('ff-branch')
ff_file_name = 'ff-file.txt'
ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
with open(ff_file, "w") as file:
file_content = "Absurd content"
file.write(file_content)
gitrepo.add(ff_file_name)
signature = Signature(user="fake user")
ff_head = gitrepo.commit(message="commit ff file", signature=signature)
gitrepo.update('master')
cs = gitrepo.merge_fastforward(
signature, other_rev=ff_head, other_branch_name='test')
self.assertEquals(len(repo.head.get_object().parents), 1)
self.assertEquals(repo.head.get_object().hex, cs.hash)
self.assertEquals(ff_head.hash, cs.hash)
self.assertTrue(os.path.isfile(ff_file))