diff --git a/paver/hg.py b/paver/hg.py index bf48278d..0fc34194 100644 --- a/paver/hg.py +++ b/paver/hg.py @@ -23,9 +23,9 @@ def clone(url, dest_folder, rev=None): None""" rev_string = '' if rev: - rev_string = '-r %s' % rev + rev_string = ' -r %s' % rev - sh('hg clone {rev} {url} {dest}'.format( + sh('hg clone{rev} {url} {dest}'.format( rev=rev_string, url=url, dest=dest_folder)) @@ -44,9 +44,15 @@ def pull(repo_path, rev=None, url=None): None""" rev_string = '' if rev: - rev_string = '-r %s' % rev + rev_string = ' -r %s' % rev - sh('hg pull {rev} -R {repo}'.format(rev=rev_string, repo=repo_path)) + url_string = '' + if url: + url_string = ' ' + url + + sh('hg pull{rev} -R {repo}{url}'.format(rev=rev_string, + repo=repo_path, + url=url_string)) def latest_tag(repo_path, relative_to='tip'): @@ -80,9 +86,9 @@ def update(repo_path, rev='tip', clean=False): None""" clean_string = '' if clean: - clean_string = '--clean' + clean_string = ' --clean' - sh('hg update -r {rev} -R {repo} {clean}'.format( + sh('hg update -r {rev} -R {repo}{clean}'.format( rev=rev, repo=repo_path, clean=clean_string)) @@ -101,13 +107,18 @@ def branches(repo_path, closed=False): closed_string = '' if closed: - closed_string = '--closed' + closed_string = ' --closed' - stdout_string = sh('hg branches -R {repo} {closed}'.format( + stdout_string = sh('hg branches -R {repo}{closed}'.format( repo=repo_path, closed=closed_string), capture=True) # Branch list comes out in the format: # : - branches = [string.split()[0] for string in stdout_string.split('\n')] + try: + branches = [line.split()[0] for line in stdout_string.split('\n') + if len(line) > 0] + except IndexError as e: + print 'std', stdout_string + print 'e', string return current_branch, branches diff --git a/paver/tests/test_hg.py b/paver/tests/test_hg.py new file mode 100644 index 00000000..0ce657ea --- /dev/null +++ b/paver/tests/test_hg.py @@ -0,0 +1,82 @@ +from mock import patch +from paver import hg + + +@patch('paver.hg.sh') +def test_simple_clone(sh): + hg.clone("ssh://foo/foo", "bar") + assert sh.called + assert sh.call_args[0][0] == "hg clone ssh://foo/foo bar" + + +@patch('paver.hg.sh') +def test_simple_clone_to_rev(sh): + hg.clone('ssh://foo/bar', 'baz', 'bam') + assert sh.called + assert sh.call_args[0][0] == 'hg clone -r bam ssh://foo/bar baz' + + +@patch('paver.hg.sh') +def test_pull_simple(sh): + hg.pull('foo') + assert sh.called + assert sh.call_args[0][0] == 'hg pull -R foo' + + +@patch('paver.hg.sh') +def test_pull_rev(sh): + hg.pull('foo', 'bar') + assert sh.called + assert sh.call_args[0][0] == 'hg pull -r bar -R foo' + + +@patch('paver.hg.sh') +def test_pull_rev_url(sh): + hg.pull('foo', 'bar', 'baz') + assert sh.called + assert sh.call_args[0][0] == 'hg pull -r bar -R foo baz', sh.call_args[0][0] + + +def test_latest_tag(): + with patch('paver.hg.sh') as sh: + sh.return_value = 'example' + + returned_value = hg.latest_tag('foo') + assert returned_value == 'example', returned_value + + +@patch('paver.hg.sh') +def test_update_simple(sh): + hg.update('foo') + assert sh.called + assert sh.call_args[0][0] == 'hg update -r tip -R foo' + + +@patch('paver.hg.sh') +def test_update_to_rev(sh): + hg.update('foo', 'bar') + assert sh.called + assert sh.call_args[0][0] == 'hg update -r bar -R foo' + + +@patch('paver.hg.sh') +def test_update_to_rev_and_clean(sh): + hg.update('foo', 'bar', True) + assert sh.called + assert sh.call_args[0][0] == 'hg update -r bar -R foo --clean' + + +@patch('paver.hg.sh') +def test_branches_with_closed(sh): + sh.side_effect = [ + 'tag1', ('branch1 123:9871230987\n' + 'branch2 456:1957091982\n')] + current_branch, branches = hg.branches('foo', True) + + assert sh.called + assert sh.call_args_list[0][0][0] == 'hg branch -R foo' + assert sh.call_args_list[1][0][0] == 'hg branches -R foo --closed' + + assert current_branch == 'tag1' + assert branches == ['branch1', 'branch2'] +