def gitrepo_remote(tmpdir): """ Setup a git repository serving as remote repository for other tests """ gitrepo = GitRepo(GitHubRepo('remote-repo', '', ''), str(tmpdir)) create_file(os.path.join(gitrepo.path, 'upstream-file')) gitrepo.commit('Commit upstream-file') # Allow pushing into a non-bare repository. with open(os.path.join(gitrepo.path, '.git', 'config'), 'a') as gitconfig: gitconfig.write('[receive]\ndenyCurrentBranch=updateInstead\n') return gitrepo
def test_gitrepo_local_nohead(tmpdir): """ Test operations on an empty git repository (commit/tag noop) """ gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir)) gitrepo.fetch_and_reset() gitrepo.describe() gitrepo.commit('Try to commit without changes') gitrepo.tag('tag') assert not gitrepo.diff() assert not gitrepo.describe() assert not gitrepo.get_hexsha()
def test_gitrepo_local_commitsquash(tmpdir): """ Test squash commiting to a git repository """ gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'testfile') create_file(testfile) gitrepo.commit('Commit testfile', squash=True) create_file(testfile, 'modified content') gitrepo.commit('Commit modified testfile', squash=True) assert '/dev/null\n+++ b/{}\n'.format( os.path.basename(testfile)) in gitrepo.diff()
def test_gitrepo_local_commitdirectory(tmpdir): """ Test commiting limited to a directory """ gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'add', 'testfile') testfile_ignored = os.path.join(gitrepo.path, 'ignored') create_file(testfile) create_file(testfile_ignored) gitrepo.commit('Commit directory `add`', directory='add') gitrepo.fetch_and_reset() assert os.path.isfile(testfile) assert not os.path.isfile(testfile_ignored)
def test_gitrepo_remote(tmpdir, gitrepo_remote): """ Test operations on a git repository with a remote """ url = 'file://{}'.format(gitrepo_remote.path) gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir)) gitrepo.fetch_and_reset() assert not gitrepo.diff() assert gitrepo.describe() assert gitrepo.get_hexsha() testfile = os.path.join(str(tmpdir), 'local-repo', 'testfile') create_file(testfile) gitrepo.commit('Commit testfile') assert gitrepo.diff()
def test_gitrepo_remote_commitsquash(tmpdir, gitrepo_remote): """ Test squash commiting """ url = 'file://{}'.format(gitrepo_remote.path) gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'testfile') gitrepo.fetch_and_reset() create_file(testfile) gitrepo.commit('Commit testfile', squash=True) create_file(testfile, 'modified content') gitrepo.commit('Commit modified testfile', squash=True) assert '/dev/null\n+++ b/{}\n'.format( os.path.basename(testfile)) in gitrepo.diff()
def test_gitrepo_local(tmpdir): """ Test operations on a local git repository """ gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'testfile') gitrepo.fetch_and_reset() create_file(testfile) gitrepo.commit('Commit testfile') gitrepo.tag('tag') assert gitrepo.diff() assert gitrepo.describe() assert gitrepo.get_hexsha() gitrepo.fetch_and_reset() assert os.path.isfile(testfile)
def test_gitrepo_remote_rebase(tmpdir, gitrepo_remote): """ Test rebasing changes instead of resetting """ url = 'file://{}'.format(gitrepo_remote.path) gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'testfile') gitrepo.fetch_and_reset() create_file(testfile) gitrepo.commit('Commit testfile') assert gitrepo.diff() gitrepo.fetch_and_reset(reset=False) assert gitrepo.diff() assert os.path.isfile(testfile) gitrepo.fetch_and_reset(reset=True) assert not gitrepo.diff() assert not os.path.isfile(testfile)
def test_gitrepo_remote_push(tmpdir, gitrepo_remote): """ Tests pushing changes to remote repository """ url = 'file://{}'.format(gitrepo_remote.path) gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir)) testfile = os.path.join(gitrepo.path, 'testfile') gitrepo.fetch_and_reset() create_file(testfile) gitrepo.commit('Commit testfile') gitrepo.push('master') gitrepo.tag('tag') gitrepo.push('master', True) gitrepo.push('somebranch', True) create_file(testfile, 'modified content') with pytest.raises(ValueError): gitrepo.push('master')
def test_gitrepo_local_commitforce(tmpdir): """ Test force committing to a git repository """ gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir)) gitignore = os.path.join(gitrepo.path, '.gitignore') testfile = os.path.join(gitrepo.path, 'testfile') create_file(gitignore, os.path.basename(testfile)) gitrepo.commit('Commit gitignore') create_file(testfile) gitrepo.commit('Try to commit ignored file') gitrepo.fetch_and_reset() assert not os.path.isfile(testfile) create_file(testfile) gitrepo.commit('Force commit ignored file', force=True) gitrepo.fetch_and_reset() assert os.path.isfile(testfile)