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_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_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_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_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)