Пример #1
0
 def test_not_bare_clone_to_not_bare(self):
     rep = gyt.repo(self._gd, init=True, bare=False)
     clone = rep.clone(self._wt2, bare=False)
     assert not gyt.is_git_dir(self._wt2)
     clone = gyt.repo(self._wt2, bare=False)
     assert clone.config('remote.origin.url') == rep.git_dir
     assert not clone.is_bare()
Пример #2
0
 def test_not_bare_clone_to_not_bare(self):
     rep = gyt.repo(self._gd, init=True, bare=False)
     clone = rep.clone(self._wt2, bare=False)
     assert not gyt.is_git_dir(self._wt2)
     clone = gyt.repo(self._wt2, bare=False)
     assert clone.config('remote.origin.url') == rep.git_dir
     assert not clone.is_bare()
Пример #3
0
 def test_bare_clone_repo(self):
     rep = gyt.repo(self._gd, init=True)
     clone = rep.clone(self._gd2, bare=True)
     clone2 = gyt.repo(self._gd2, bare=True)
     assert clone.config('remote.origin.url') == self._gd
     assert clone.is_bare()
     clone2 = gyt.repo(self._gd2)
     assert clone2.config('remote.origin.url') == self._gd
     assert clone2.is_bare()
Пример #4
0
 def test_bare_clone_repo(self):
     rep = gyt.repo(self._gd, init=True)
     clone = rep.clone(self._gd2, bare=True)
     clone2 = gyt.repo(self._gd2, bare=True)
     assert clone.config('remote.origin.url') == self._gd
     assert clone.is_bare()
     clone2 = gyt.repo(self._gd2)
     assert clone2.config('remote.origin.url') == self._gd
     assert clone2.is_bare()
Пример #5
0
 def _commit(self, repo, filename, content='testcontent',
             message='testmessage'):
     # TODO allow commiting more than one file
     assert os.path.exists(repo.work_tree), \
         "repo.work_tree must exist, check if repo has been created with bare=False"  # noqa
     f = open(os.path.join(repo.work_tree, filename), 'w')
     f.write(content)
     f.close()
     rep2 = gyt.repo(repo.path, repo.work_tree, bare=False)
     rep2.call(['add', filename])
     rep2.call(['commit', filename, '-m', message], _env=self.env_for_git)
     return gyt.repo(repo.path).sha()
Пример #6
0
 def _commit(self,
             repo,
             filename,
             content='testcontent',
             message='testmessage'):
     # TODO allow commiting more than one file
     assert os.path.exists(repo.work_tree), \
         "repo.work_tree must exist, check if repo has been created with bare=False"  # noqa
     f = open(os.path.join(repo.work_tree, filename), 'w')
     f.write(content)
     f.close()
     rep2 = gyt.repo(repo.path, repo.work_tree, bare=False)
     rep2.call(['add', filename])
     rep2.call(['commit', filename, '-m', message], _env=self.env_for_git)
     return gyt.repo(repo.path).sha()
Пример #7
0
 def test_rename_detection(self):
     repo = self._repo('test', bare=False)
     self._commit(repo, 'testfile', 'content', 'msg1')
     grepo = gyt.repo(repo.path, work_tree=repo.work_tree)
     grepo.call('mv testfile testfile_new')
     grepo.call('commit -mmv', _env=self.env_for_git)
     assert repo.rename_detection('HEAD') == {'testfile_new': 'testfile'}
 def _commit(self, repo, filename, content="testcontent", message="testmessage"):
     # TODO allow commiting more than one file
     assert os.path.exists(
         repo.work_tree
     ), "repo.work_tree must exist, check if repo has been created with bare=False"  # noqa
     path = os.path.join(repo.work_tree, filename)
     dir_ = os.path.dirname(path)
     if not os.path.exists(dir_):
         os.makedirs(os.path.dirname(path))
     f = open(path, "w")
     f.write(content)
     f.close()
     rep2 = gyt.repo(repo.path, repo.work_tree, bare=False)
     rep2.call(["add", filename])
     rep2.call(["commit", filename, "-m", message], _env=self.env_for_git)
     return gyt.repo(repo.path).sha()
Пример #9
0
 def test_rename_detection(self):
     repo = self._repo('test', bare=False)
     self._commit(repo, 'testfile', 'content', 'msg1')
     grepo = gyt.repo(repo.path, work_tree=repo.work_tree)
     grepo.call('mv testfile testfile_new')
     grepo.call('commit -mmv', _env=self.env_for_git)
     assert repo.rename_detection('HEAD') == {'testfile_new': 'testfile'}
Пример #10
0
 def __init__(self, path, work_tree=None, project=None):
     self.path = path
     self.work_tree = work_tree
     self.project = project
     self.project_name = project.name if project else ''
     # TODO check, shouldn't we pass work_tree to gyt repo?
     # be careful it would change a lot of things behind
     # getting not bare repos if inited with work_tree
     self._gyt_repo = gyt.repo(self.path)
     self.pygit2_repo = self._gyt_repo.repo
Пример #11
0
 def __init__(self, path, work_tree=None, project=None):
     self.path = path
     self.work_tree = work_tree
     self.project = project
     self.project_name = project.name if project else ''
     # TODO check, shouldn't we pass work_tree to gyt repo?
     # be careful it would change a lot of things behind
     # getting not bare repos if inited with work_tree
     self._gyt_repo = gyt.repo(self.path)
     self.pygit2_repo = self._gyt_repo.repo
Пример #12
0
 def _commit_push(self, proj, objs, msg='testmsg', author=T_AUTHOR,
                  author_email=T_AUTHOR_EMAIL):
     repo = gyt.repo(proj.git.path)
     clone_path = self._path_for_clone(proj.name)
     if os.path.exists(clone_path):
         clone = gyt.repo(clone_path, bare=False)
     else:
         clone = repo.clone(clone_path, bare=False)
     # TODO allow commiting more than one file
     # assert os.path.exists(repo.work_tree), \
     # noqa "repo.work_tree must exist, check if repo has been created with bare=False"
     for filename, content in objs:
         f = open(os.path.join(clone.work_tree, filename), 'w')
         f.write(content)
         f.close()
         clone.call(['add', filename])
     clone.call(['commit', '--author', '%s <%s>' % (
         author, author_email), '-m', msg], _env=self.env_for_git)
     clone.call('push origin HEAD')
     return clone.sha()
Пример #13
0
 def test_rename_detection_with_manual_mv(self):
     repo = self._repo('test', bare=False)
     content1 = 'a\na\na\na\na\na\na\na\na\na\nAAA'
     self._commit(repo, 'testfile', content1, 'msg1')
     with open(os.path.join(repo.work_tree, 'testfile_new'), 'w') as f:
         f.write(content1)
     grepo = gyt.repo(repo.path, work_tree=repo.work_tree)
     grepo.call('rm testfile')
     grepo.call('add testfile_new')
     grepo.call('commit -ammv', _env=self.env_for_git)
     assert repo.rename_detection('HEAD') == {'testfile_new': 'testfile'}
Пример #14
0
 def _commit_push(self, proj, objs, msg='testmsg', author=T_AUTHOR,
                  author_email=T_AUTHOR_EMAIL):
     repo = gyt.repo(proj.git.path)
     clone_path = self._path_for_clone(proj.name)
     if os.path.exists(clone_path):
         clone = gyt.repo(clone_path, bare=False)
     else:
         clone = repo.clone(clone_path, bare=False)
     # TODO allow commiting more than one file
     # assert os.path.exists(repo.work_tree), \
     # noqa "repo.work_tree must exist, check if repo has been created with bare=False"
     for filename, content in objs:
         f = open(os.path.join(clone.work_tree, filename), 'w')
         f.write(content)
         f.close()
         clone.call(['add', filename])
     clone.call(['commit', '--author', '%s <%s>' % (
         author, author_email), '-m', msg], _env=self.env_for_git)
     clone.call('push origin HEAD')
     return clone.sha()
Пример #15
0
 def test_rename_detection_with_manual_mv(self):
     repo = self._repo('test', bare=False)
     content1 = 'a\na\na\na\na\na\na\na\na\na\nAAA'
     self._commit(repo, 'testfile', content1, 'msg1')
     with open(os.path.join(repo.work_tree, 'testfile_new'), 'w') as f:
         f.write(content1)
     grepo = gyt.repo(repo.path, work_tree=repo.work_tree)
     grepo.call('rm testfile')
     grepo.call('add testfile_new')
     grepo.call('commit -ammv', _env=self.env_for_git)
     assert repo.rename_detection('HEAD') == {'testfile_new': 'testfile'}
Пример #16
0
 def test_git_repo_with_space(self):
     gd_with_space = self._gd + ' with space and 中文'
     wt_with_space = self._wt + ' with space and 中文'
     os.mkdir(gd_with_space)
     os.mkdir(wt_with_space)
     rep = gyt.repo(gd_with_space, wt_with_space, init=True)
     self._add_file(
         rep, 'test_filename', 'content', commit=True, commit_msg='test')
     assert rep
     h = rep.logs()
     assert h
     shutil.rmtree(gd_with_space)
     shutil.rmtree(wt_with_space)
Пример #17
0
 def test_branches(self):
     repo = self._repo('test_branches', bare=False)
     rep2 = gyt.repo(repo.path, repo.work_tree, bare=False)
     assert repo.get_branches() == []
     self._commit(repo, 'testfile')
     assert repo.get_branches() == ['master']
     rep2.call(['branch', 'test_branch'])
     assert repo.get_branches() == ['master', 'test_branch']
     rep2.call(['checkout', 'test_branch'])
     assert repo.get_branches() == ['test_branch', 'master']
     rep2.call(['branch', 'test_branch牛逼'])
     assert repo.get_branches(
     ) == ['test_branch', 'master', u'test_branch\u725b\u903c']
Пример #18
0
 def test_merge_commit(self):
     repo = self._repo('test_merge_diff', bare=False)
     self._commit(repo, 'testfile', 'msg')
     not_bare = gyt.repo(repo.path, repo.work_tree)
     self._commit(repo, 'tf1', 'content1', 'msg1')
     not_bare.call('checkout -b test_br')
     sha2 = self._commit(repo, 'tf2', 'content2', 'msg2')
     not_bare.call('checkout master')
     self._commit(repo, 'tf3', 'content3', 'msg3')
     not_bare.call('merge test_br', _env=self.env_for_git)
     sha_merge = repo.pygit2_repo.revparse_single('HEAD').hex
     c = repo.get_commit(sha_merge)
     assert c.parent == sha2, \
         "This is bad, only one parent for a merge commit"
Пример #19
0
 def test_branches(self):
     repo = self._repo('test_branches', bare=False)
     rep2 = gyt.repo(repo.path, repo.work_tree, bare=False)
     assert repo.get_branches() == []
     self._commit(repo, 'testfile')
     assert repo.get_branches() == ['master']
     rep2.call(['branch', 'test_branch'])
     assert repo.get_branches() == ['master', 'test_branch']
     rep2.call(['checkout', 'test_branch'])
     assert repo.get_branches() == ['test_branch', 'master']
     rep2.call(['branch', 'test_branch牛逼'])
     assert repo.get_branches() == [
         'test_branch', 'master', u'test_branch\u725b\u903c'
     ]
Пример #20
0
 def test_merge_commit(self):
     repo = self._repo('test_merge_diff', bare=False)
     self._commit(repo, 'testfile', 'msg')
     not_bare = gyt.repo(repo.path, repo.work_tree)
     sha1 = self._commit(repo, 'tf1', 'content1', 'msg1')
     not_bare.call('checkout -b test_br')
     sha2 = self._commit(repo, 'tf2', 'content2', 'msg2')
     not_bare.call('checkout master')
     sha3 = self._commit(repo, 'tf3', 'content3', 'msg3')
     not_bare.call('merge test_br', _env=self.env_for_git)
     sha_merge = repo.pygit2_repo.revparse_single('HEAD').hex
     c = repo.get_commit(sha_merge)
     assert c.parent == sha2, \
         "This is bad, only one parent for a merge commit"
Пример #21
0
 def test_parse_merge_diff_empty(self):
     repo = self._repo('test_merge_diff', bare=False)
     self._commit(repo, 'testfile', 'msg')
     not_bare = gyt.repo(repo.path, repo.work_tree)
     assert not not_bare.is_bare()
     self._commit(repo, 'tf1', 'content1', 'msg1')
     not_bare.call('checkout -b test_br')
     sha2 = self._commit(repo, 'tf2', 'content2', 'msg2')
     not_bare.call('checkout master')
     sha3 = self._commit(repo, 'tf3', 'content3', 'msg3')
     not_bare.call('merge test_br', _env=self.env_for_git)
     sha_merge = repo.pygit2_repo.revparse_single('HEAD').hex
     diff = repo.parse_diff(sha_merge)
     assert diff['body'] == ''
     assert len(diff['difflist']) == 1
     assert diff['parents'] == '%s %s' % (sha3, sha2)
Пример #22
0
 def test_parse_merge_diff_empty(self):
     repo = self._repo('test_merge_diff', bare=False)
     self._commit(repo, 'testfile', 'msg')
     not_bare = gyt.repo(repo.path, repo.work_tree)
     assert not not_bare.is_bare()
     self._commit(repo, 'tf1', 'content1', 'msg1')
     not_bare.call('checkout -b test_br')
     sha2 = self._commit(repo, 'tf2', 'content2', 'msg2')
     not_bare.call('checkout master')
     sha3 = self._commit(repo, 'tf3', 'content3', 'msg3')
     not_bare.call('merge test_br', _env=self.env_for_git)
     sha_merge = repo.pygit2_repo.revparse_single('HEAD').hex
     diff = repo.parse_diff(sha_merge)
     assert diff['body'] == ''
     assert len(diff['difflist']) == 1
     assert diff['parents'] == '%s %s' % (sha3, sha2)
Пример #23
0
 def test_git_repo_with_space(self):
     gd_with_space = self._gd + ' with space and 中文'
     wt_with_space = self._wt + ' with space and 中文'
     os.mkdir(gd_with_space)
     os.mkdir(wt_with_space)
     rep = gyt.repo(gd_with_space, wt_with_space, init=True)
     self._add_file(rep,
                    'test_filename',
                    'content',
                    commit=True,
                    commit_msg='test')
     assert rep
     h = rep.logs()
     assert h
     shutil.rmtree(gd_with_space)
     shutil.rmtree(wt_with_space)
 def test_simple_commit_in_branch_in_subdir(self):
     repo = self._repo("test", bare=False)
     self._commit(repo, "test/file1", "content1", "msg1")
     tmp_branch = repo.temp_branch_name()
     repo.commit_one_file(
         "test/file1", "content1 modified", "change1", self.u, orig_hash=hash("content1"), branch=tmp_branch
     )
     with mkdtemp() as tmpdir:
         gyt.call(["git", "clone", repo.path, tmpdir])
         repo_check = gyt.repo(tmpdir, bare=False)
         src = repo_check.call("show HEAD:test/file1")
         assert src == u"content1"
         repo_check.call("checkout master")
         src = repo_check.call("show HEAD:test/file1")
         assert src == u"content1"
         repo_check.call("checkout %s" % tmp_branch)
         src = repo_check.call("show HEAD:test/file1")
         assert src == u"content1 modified"
         repo_check.call("checkout master")
         src = repo_check.call("show HEAD:test/file1")
         assert src == u"content1"
Пример #25
0
 def test_simple_commit_in_branch_in_subdir(self):
     repo = self._repo('test', bare=False)
     self._commit(repo, 'test/file1', 'content1', 'msg1')
     tmp_branch = repo.temp_branch_name()
     repo.commit_one_file('test/file1', 'content1 modified', 'change1',
                          self.u, orig_hash=hash('content1'),
                          branch=tmp_branch)
     with mkdtemp() as tmpdir:
         gyt.call(['git', 'clone', repo.path, tmpdir])
         repo_check = gyt.repo(tmpdir, bare=False)
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
         repo_check.call('checkout master')
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
         repo_check.call('checkout %s' % tmp_branch)
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1 modified'
         repo_check.call('checkout master')
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
Пример #26
0
 def test_simple_commit_in_branch_in_subdir(self):
     repo = self._repo('test', bare=False)
     self._commit(repo, 'test/file1', 'content1', 'msg1')
     tmp_branch = repo.temp_branch_name()
     repo.commit_one_file('test/file1',
                          'content1 modified',
                          'change1',
                          self.u,
                          orig_hash=hash('content1'),
                          branch=tmp_branch)
     with mkdtemp() as tmpdir:
         gyt.call(['git', 'clone', repo.path, tmpdir])
         repo_check = gyt.repo(tmpdir, bare=False)
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
         repo_check.call('checkout master')
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
         repo_check.call('checkout %s' % tmp_branch)
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1 modified'
         repo_check.call('checkout master')
         src = repo_check.call('show HEAD:test/file1')
         assert src == u'content1'
Пример #27
0
 def test_init_repo(self):
     rep = gyt.repo(self._gd, self._wt, init=True)
     assert rep.git_dir == self._gd
     assert not rep.is_bare()
Пример #28
0
 def test_init_repo(self):
     rep = gyt.repo(self._gd, self._wt, init=True)
     assert rep.git_dir == self._gd
     assert not rep.is_bare()
Пример #29
0
 def test_init_repo_and_get(self):
     rep = gyt.repo(self._gd, init=True)
     assert rep
     rep2 = gyt.repo(self._gd)
     assert rep2
     assert rep.git_dir == rep2.git_dir
Пример #30
0
 def test_is_git_dir(self):
     assert not gyt.is_git_dir(self._gd)
     gyt.repo(self._gd, init=True)
     assert gyt.is_git_dir(self._gd)
Пример #31
0
 def get_branches(self):
     '''returns list of (local) branches, with active (= HEAD) one being
     the first item'''
     return gyt.repo(self.path).refs(select='branches',
                                     short=True,
                                     current_first=True)
Пример #32
0
 def clone_git(self, to_path):
     git_path = os.path.join(self.repo_root_path, self.git_path)
     to_path = os.path.join(self.repo_root_path, to_path)
     rep = gyt.repo(git_path)
     rep.clone(to_path)
Пример #33
0
 def test_git_init_with_spaces(self):
     gyt.repo(self._gds, init=True)
     assert gyt.is_git_dir(self._gds)
Пример #34
0
 def test_git_call_init(self):
     gyt.repo(self._gd, init=True)
     assert os.path.exists(self._gd)
     assert os.path.exists(opj(self._gd, 'refs'))
Пример #35
0
 def get_branches(self):
     '''returns list of (local) branches, with active (= HEAD) one being
     the first item'''
     return gyt.repo(self.path).refs(select='branches', short=True,
                                     current_first=True)
Пример #36
0
 def test_is_git_dir(self):
     assert not gyt.is_git_dir(self._gd)
     gyt.repo(self._gd, init=True)
     assert gyt.is_git_dir(self._gd)
Пример #37
0
 def get_tags(self):
     return gyt.repo(self.path).refs(select='tags', short=True)
Пример #38
0
 def test_init_repo_default_behavior(self):
     rep = gyt.repo(self._wt, bare=False, init=True)
     assert not rep.is_bare()
     assert rep.work_tree == self._wt
     assert rep.git_dir == opj(self._wt, gyt.GIT_DIR_DEFAULT)
Пример #39
0
 def test_cannot_double_init(self):
     rep1 = gyt.repo(self._gd, init=True)
     assert rep1
     gyt.repo(self._gd, init=True)
Пример #40
0
 def test_init_repo_and_get(self):
     rep = gyt.repo(self._gd, init=True)
     assert rep
     rep2 = gyt.repo(self._gd)
     assert rep2
     assert rep.git_dir == rep2.git_dir
Пример #41
0
 def create_git_repo(cls, git_path):
     git_path = os.path.join(get_repo_root(), git_path)
     #check_call(['git', 'init', '--bare', git_path])
     gyt.repo(git_path, init=True)
Пример #42
0
 def test_git_call_init(self):
     gyt.repo(self._gd, init=True)
     assert os.path.exists(self._gd)
     assert os.path.exists(opj(self._gd, 'refs'))
Пример #43
0
 def _repo(self, bare=False):
     if bare:
         rep = gyt.repo(self._gd, bare=True, init=True)
     else:
         rep = gyt.repo(self._gd, self._wt, bare=False, init=True)
     return rep
Пример #44
0
 def test_init_repo_default_behavior(self):
     rep = gyt.repo(self._wt, bare=False, init=True)
     assert not rep.is_bare()
     assert rep.work_tree == self._wt
     assert rep.git_dir == opj(self._wt, gyt.GIT_DIR_DEFAULT)
Пример #45
0
 def _repo(self, bare=False):
     if bare:
         rep = gyt.repo(self._gd, bare=True, init=True)
     else:
         rep = gyt.repo(self._gd, self._wt, bare=False, init=True)
     return rep
Пример #46
0
 def test_cannot_double_init(self):
     rep1 = gyt.repo(self._gd, init=True)
     assert rep1
     gyt.repo(self._gd, init=True)
Пример #47
0
 def test_git_init_with_chinese(self):
     gyt.repo(self._gdc, init=True)
     assert gyt.is_git_dir(self._gdc)
Пример #48
0
 def create_git_repo(cls, git_path):
     git_path = os.path.join(get_repo_root(), git_path)
     #check_call(['git', 'init', '--bare', git_path])
     gyt.repo(git_path, init=True)
Пример #49
0
 def get_tags(self):
     return gyt.repo(self.path).refs(select='tags', short=True)
Пример #50
0
 def clone_git(self, to_path):
     git_path = os.path.join(self.repo_root_path, self.git_path)
     to_path = os.path.join(self.repo_root_path, to_path)
     rep = gyt.repo(git_path)
     rep.clone(to_path)
Пример #51
0
 def test_git_init_with_spaces(self):
     gyt.repo(self._gds, init=True)
     assert gyt.is_git_dir(self._gds)
Пример #52
0
 def test_git_init_with_chinese(self):
     gyt.repo(self._gdc, init=True)
     assert gyt.is_git_dir(self._gdc)