def test_existing_repo(): r = repo(tmp, 'test-repo', clone_url='ssh://git@localhost:2222/test_remote_repo', branch=None) r2 = repo(tmp, 'test-repo') assert r2._remote == 'ssh://git@localhost:2222/test_remote_repo'
def create_test_repo(repo_name, empty=False, ensure_new=True): if repo_name in _test_repos: if not ensure_new: return remove_test_repo(repo_name) if not os.path.isdir(wds): os.mkdir(wds) manager = Gitolite(path=os.path.join(wds, 'gitolite-admin'), url=test_settings['gitolite_url']) manager.create_repo(repo_name) manager.add_rule(repo_name, 'RW+', ['@all']) manager.save() if not empty: r = repo(wds, repo_name, clone_url='ssh://git@localhost:2222/' + repo_name, branch=None) readme = open(os.path.join(r._workdir, test_file), 'w') readme.write(test_contents) readme.close() r.stage(test_file) r.commit("Initial commit") r.push() rm('-rf', wds) _test_repos.append(repo_name)
def test_clone(): r = repo(tmp, 'test-repo', clone_url='ssh://git@localhost:2222/test_remote_repo', branch=None) assert os.path.isdir(os.path.join(tmp, 'test-repo')) assert os.path.isdir(os.path.join(tmp, 'test-repo/.git'))
def test_clone_bare(): r = repo(tmp, 'test-repo', clone_url='ssh://git@localhost:2222/test_remote_repo', bare=True, branch=None) assert os.path.isdir(os.path.join(tmp, 'test-repo')) assert os.path.isfile(os.path.join(tmp, 'test-repo/config'))
def test_push(): r = repo(tmp, 'test-repo', clone_url='ssh://git@localhost:2222/test_remote_repo', branch=None) readme = open(os.path.join(r._workdir, 'README.md'), 'w') readme.write("This is a random readme:" + str(random.random())) readme.close() r.stage('README.md') r.commit("Test commit") r.push() rm('-rf', r._workdir) r = repo(tmp, 'test-repo', clone_url='ssh://git@localhost:2222/test_remote_repo', branch=None) readme = open(os.path.join(r._workdir, 'README.md'), 'r').read() assert readme.startswith('This is a random readme:')
def test_read_repo(): r = repo(tmp, 'test-repo') a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('ahoj') a.close() r.stage('a') r.commit(commit_message='MSG') assert r.read('a') == 'ahoj' a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('cau') a.close() r.stage('a') r.commit(commit_message='MSG') assert r.read('a') == 'cau' assert r.read('a', revision='HEAD^') == 'ahoj'
def test_ls_repo(): r = repo(tmp, 'test-repo') a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('ahoj') a.close() assert len(r.ls_staged()) == 0 assert r.ls_unstaged() == ['a'] assert r.ls_unstaged(include_untracked=False) == [] r.stage('a') assert r.ls_staged() == ['a'] assert r.ls_unstaged() == [] r.commit(commit_message='MSG') a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('cau') assert r.ls_unstaged() == ['a'] assert r.ls_unstaged(include_untracked=False) == ['a']
def test_ls_tree_repo(): r = repo(tmp, 'test-repo') a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('ahoj') a.close() r.stage('a') r.commit(commit_message='MSG') r.rm('a') r.commit(commit_message='MSG') assert r.ls_tree() == [] a = open(os.path.join(tmp, 'test-repo/a'), 'w') a.write('ahoj') a.close() r.stage('a') r.commit(commit_message='MSG') assert r.ls_tree() == ['a'] os.mkdir(os.path.join(tmp, 'test-repo/b')) c = open(os.path.join(tmp, 'test-repo/b/c'), 'w') c.write('cau') c.close() r.stage('b/c') r.commit(commit_message='MSG') assert sorted(r.ls_tree()) == sorted(['a', 'b/c']) assert sorted(r.ls_tree(tree='HEAD^')) == sorted(['a'])
def test_init_repo(): r = repo(tmp, 'test-repo') assert os.path.isdir(os.path.join(tmp, 'test-repo')) assert os.path.isfile(os.path.join(tmp, 'test-repo/.git/config'))