Detailed tests of git.py ======================== .. :doctest: .. :setup: zest.releaser.tests.functional.setup .. :teardown: zest.releaser.tests.functional.teardown Some initial imports: >>> from zest.releaser import git >>> from zest.releaser.utils import execute_command >>> import os Project name ------------ The prepared git project has a setup.py, so the name in there is used: >>> os.chdir(gitsourcedir) >>> checkout = git.Git() >>> checkout.name 'tha.example' When the setup.py doesn't exist or doesn't return a proper name, we fall back to the directory name. >>> orig = checkout.get_setup_py_name >>> checkout.get_setup_py_name= lambda: None # Hack >>> checkout.name 'tha.example-git' >>> checkout.get_setup_py_name = orig # Restore hack Diff and commit --------------- Make a change: >>> setup_py = os.path.join(gitsourcedir, 'setup.py') >>> dont_care = open(setup_py, 'a').write('\na = 2\n') >>> cmd = checkout.cmd_diff() >>> cmd 'git diff' >>> print(execute_command(cmd)) diff --git a/setup.py b/setup.py index 9c14143..54fa3b9 100644 --- a/setup.py +++ b/setup.py @@ -36,3 +36,5 @@ setup(name='tha.example', 'console_scripts': [ ]}, ) + +a = 2 Commit it: >>> cmd = checkout.cmd_commit('small tweak') >>> cmd 'git commit -a -m "small tweak"' In some cases we get this output: ``[master ...] small tweak`` and in other this: ``Created commit ...: small tweak`` >>> print('dummy %s' % execute_command(cmd)) dummy...small tweak 1 files changed, 2 insertions(+), 0 deletions(-) Tags ---- Originally there are no tags: >>> checkout.available_tags() [] Create a tag and it will show up: >>> cmd = checkout.cmd_create_tag('0.1') >>> cmd 'git tag 0.1 -m "Tagging 0.1"' >>> dont_care = execute_command(cmd) >>> checkout.available_tags() ['0.1'] A specific tag url is important for subversion, but nonsensical for git. We just return the version as-is: >>> checkout.tag_url('holadijee') 'holadijee' Make and commit a small change: >>> dont_care = open(setup_py, 'a').write('\nb = 3\n') >>> cmd = checkout.cmd_commit('small tweak') >>> print('dummy %s' % execute_command(cmd)) dummy...small tweak 1 files changed, 2 insertions(+), 0 deletions(-) Now we can request the changes since a specific tag: >>> cmd = checkout.cmd_diff_last_commit_against_tag('0.1') >>> cmd 'git diff 0.1' >>> print(execute_command(cmd)) diff --git a/setup.py b/setup.py index 9c14143..54fa3b9 100644 --- a/setup.py +++ b/setup.py @@ -38,3 +38,5 @@ setup(name='tha.example', ) a = 2 + +b = 3 Making a tag checkout --------------------- For checking out a tag with subversion or mercurial, we first create a temp dir and afterwards do a checkout/clone of a tag. With git, we immediately make a clone of the repository in a tempdir and afterwards switch ("checkout") that directory to the tag. For checking out a tag, we first need a temporary dir with a clone of the repository. >>> temp = checkout.prepare_checkout_dir('somename') >>> temp 'TMPDIR/somename...' >>> os.path.isdir(temp) True The checked out clone is really a clone and not an empty directory. The setup.py also contains our latest "b = 3" change: >>> sorted(os.listdir(temp)) ['.git', '.gitignore', 'CHANGES.txt', ...] >>> print(open(os.path.join(temp, 'setup.py')).read()) from setuptools import setup, find_packages ... b = 3 For git, we have to change to that directory! Git doesn't work with paths. >>> cmd = checkout.cmd_checkout_from_tag('0.1', temp) Traceback (most recent call last): ... RuntimeError: SYSTEM EXIT (code=1) Chdir and make a tag checkout: >>> os.chdir(temp) >>> cmd = checkout.cmd_checkout_from_tag('0.1', temp) >>> cmd 'git checkout 0.1 && git submodule update --init --recursive' >>> print(execute_command(cmd)) RED Note: ...0.1... RED HEAD is now at ... small tweak The tempdir should be at tag 0.1. The last line ought to be "a = 2" >>> print(open(os.path.join(temp, 'setup.py')).read()) from setuptools import setup, find_packages ... a = 2 Pushing changes --------------- For git, committing isn't enough. We need to push changes to the server: >>> checkout.push_commands() ['git push', 'git push --tags']