1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
# vim: set fileencoding=utf-8 :
#
# (C) 2017 Guido Günther <agx@sigxcpu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, please see
# <http://www.gnu.org/licenses/>
import subprocess
from tests.component import ComponentTestBase
from tests.component.deb.fixtures import RepoFixtures
from tests.testutils import skip_without_cmd
from gbp.git import GitRepository
from gbp.scripts.push import main as push
class TestPush(ComponentTestBase):
"""Test pushing to remote repos"""
def setUp(self):
ComponentTestBase.setUp(self)
self.target = GitRepository.create('target', bare=True)
@RepoFixtures.native()
def test_push_native(self, repo):
repo.add_remote_repo('origin', self.target.path)
self.assertEqual(push(['argv0']), 0)
self._check_repo_state(self.target, 'master',
['master'],
tags=['debian/0.4.14'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.quilt30()
def test_push_upstream(self, repo):
repo.add_remote_repo('origin', self.target.path)
self.assertEqual(push(['argv0']), 0)
self._check_repo_state(self.target, 'master',
['master', 'upstream'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.quilt30(opts=['--pristine-tar'])
def test_push_pristine_tar(self, repo):
repo.add_remote_repo('origin', self.target.path)
self.assertEqual(push(['argv0', '--pristine-tar']), 0)
self._check_repo_state(self.target, 'master',
['master', 'upstream', 'pristine-tar'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.quilt30(opts=['--pristine-tar'])
def test_push_detached_head(self, repo):
repo.checkout("HEAD^{commit}")
repo.add_remote_repo('origin', self.target.path)
self.assertEqual(push(['argv0', '--ignore-branch']), 0)
# Since branch head is detached we don't push it but upstream
# branch and tags must be there:
self._check_repo_state(self.target, None,
['upstream'],
tags=['debian/2.8-1', 'upstream/2.8'])
@RepoFixtures.quilt30()
def test_push_skip_upstream(self, repo):
repo.add_remote_repo('origin', self.target.path)
self.assertEqual(push(['argv0', '--upstream-branch=']), 0)
self._check_repo_state(self.target, 'master',
['master'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.native()
def test_push_tag_ne_branch(self, repo):
repo.add_remote_repo('origin', self.target.path)
self.add_file(repo, "foo.txt", "foo")
self.assertEqual(push(['argv0']), 0)
self._check_repo_state(self.target, 'master',
['master'],
tags=['debian/0.4.14'])
self.assertEqual(repo.rev_parse("HEAD^"),
self.target.head)
@RepoFixtures.quilt30()
def test_not_debian_branch(self, repo):
repo.add_remote_repo('origin', self.target.path)
repo.create_branch("foo")
repo.set_branch("foo")
self.assertEqual(push(['argv0']), 1)
self._check_log(-2, ".*You are not on branch 'master' but on 'foo'")
@skip_without_cmd('debchange')
@RepoFixtures.quilt30()
def test_dont_push_unreleased(self, repo):
repo.add_remote_repo('origin', self.target.path)
subprocess.check_call(["debchange", "-i", "foo"])
self.assertEqual(push(['argv0']), 0)
self._check_repo_state(self.target, None,
['upstream'],
tags=['upstream/2.8'])
@RepoFixtures.quilt30()
def test_push_not_origin(self, repo):
repo.add_remote_repo('notorigin', self.target.path)
self.assertEqual(push(['argv0', 'notorigin']), 0)
self._check_repo_state(self.target, 'master',
['master', 'upstream'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.quilt30()
def test_push_not_origin_detect(self, repo):
repo.add_remote_repo('notorigin', self.target.path)
repo.set_config("branch.master.remote", "notorigin")
repo.set_config("branch.master.merge", "refs/heads/master")
self.assertEqual(push(['argv0']), 0)
self._check_repo_state(self.target, 'master',
['master', 'upstream'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
@RepoFixtures.quilt30()
def test_push_failure(self, repo):
"""
Check that in case of failure we push all other branches/tags
"""
repo.add_remote_repo('origin', self.target.path)
# Make the upstream branch not fast forwardable so pushing to it fails
repo.push('origin', 'master')
self.target.create_branch('upstream', 'master')
self.assertEqual(push(['argv0']), 1)
self._check_repo_state(self.target, 'master',
['master', 'upstream'],
tags=['debian/2.8-1', 'upstream/2.8'])
self.assertEqual(repo.head, self.target.head)
self._check_in_log('.*Error running git push: To.*/target')
self._check_log(-1, ".*Failed to push some refs")
|