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()
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()
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()
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()
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
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()
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'}
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_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']
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"
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' ]
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"
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)
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"
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'
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()
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
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)
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)
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)
def test_git_init_with_spaces(self): gyt.repo(self._gds, init=True) assert gyt.is_git_dir(self._gds)
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'))
def get_tags(self): return gyt.repo(self.path).refs(select='tags', short=True)
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)
def test_cannot_double_init(self): rep1 = gyt.repo(self._gd, init=True) assert rep1 gyt.repo(self._gd, init=True)
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)
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
def test_git_init_with_chinese(self): gyt.repo(self._gdc, init=True) assert gyt.is_git_dir(self._gdc)