Esempio n. 1
0
    def test_pull_all(self, repo):
        """Test the '--all' commandline option"""
        # Create new branch in repo
        repo.create_branch('foob')

        # Clone and create new commits in origin
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', '--all', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        tmp_workdir = os.path.join(self._tmpdir, 'tmp_workdir')
        os.mkdir(tmp_workdir)
        with open(os.path.join(tmp_workdir, 'new_file'), 'w'):
            pass
        repo.commit_dir(tmp_workdir, 'New commit in master', branch='master')
        repo.commit_dir(tmp_workdir, 'New commit in foob', branch='foob')

        # Check that the branch is not updated when --all is not used
        eq_(pull(['argv0']), 0)
        eq_(len(cloned.get_commits(until='master')), 3)
        eq_(len(cloned.get_commits(until='upstream')), 1)
        eq_(len(cloned.get_commits(until='foob')), 2)

        # Check that --all updates all branches
        repo.commit_dir(tmp_workdir, 'New commit in upstream', branch='upstream')
        eq_(pull(['argv0', '--all']), 0)
        eq_(len(cloned.get_commits(until='foob')), 3)
        eq_(len(cloned.get_commits(until='upstream')), 2)
Esempio n. 2
0
    def test_setup_gitattrs_dgit34(self, repo):
        """Test that setting up Git attributes manually works even with a very old dgit"""
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])

        attrs_file = os.path.join(dest, '.git', 'info', 'attributes')

        # file shouldn’t exist at this point yet
        self.assertFalse(
            os.path.exists(attrs_file) and os.path.getsize(attrs_file),
            "%s is non-empty" % attrs_file)

        with open(attrs_file, 'w') as f:
            f.write('\n'.join(dgit34_attributes))

        os.chdir(cloned.path)
        setup_gitattributes(['arg0', '--verbose'])

        ok_(os.path.exists(attrs_file), "%s is missing" % attrs_file)

        with open(attrs_file) as f:
            attrs = sorted(f.read().splitlines())

        expected_gitattrs = sorted(sorted_gitattrs + [
            '# Old dgit macro disabled:',
            '# [attr]dgit-defuse-attrs\t-text -eol -crlf -ident -filter',
            '# ^ see dgit(7).  To undo, leave a definition of [attr]dgit-defuse-attrs',
        ])

        self.assertEquals(attrs, expected_gitattrs)
Esempio n. 3
0
    def test_clone_with_attrs(self, repo):
        """Test that cloning a repo with harmful attrs disarms them"""
        with open('.gitattributes', 'w') as f:
            f.write('# not empty')
        repo.add_files('.gitattributes')
        repo.commit_files('.gitattributes', msg="add .gitattributes")

        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])

        attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
        ok_(os.path.exists(attrs_file), "%s is missing" % attrs_file)

        with open(attrs_file) as f:
            attrs = sorted(f.read().splitlines())

        expected_gitattrs = [
            '# Added by git-buildpackage to disable .gitattributes found in the upstream tree',
            '* -export-ignore',
            '* -export-subst',
            '* dgit-defuse-attrs',
            '[attr]dgit-defuse-attrs  -text -eol -crlf -ident -filter -working-tree-encoding',
        ]
        self.assertEquals(attrs, expected_gitattrs)
Esempio n. 4
0
 def test_pull_default_remote(self, repo):
     """Test that pulling of debian native packages works (default remote)"""
     dest = os.path.join(self._tmpdir, 'cloned_repo')
     clone(['arg0', repo.path, dest])
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'master', ['master'])
     eq_(pull(['argv0']), 0)
     assert len(repo.get_commits()) == 1
Esempio n. 5
0
 def test_clone_native(self, repo):
     """Test that cloning of debian native packages works"""
     dest = os.path.join(self._tmpdir, 'cloned_repo')
     clone(
         ['arg0', '--postclone=printenv > postclone.out', repo.path, dest])
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'master', ['master'])
     assert len(cloned.get_commits()) == 1
     self.check_hook_vars('postclone', ["GBP_GIT_DIR"])
Esempio n. 6
0
 def test_clone_native(self, repo):
     """Test that cloning of debian native packages works"""
     dest = os.path.join(self._tmpdir,
                         'cloned_repo')
     clone(['arg0',
            '--postclone=printenv > ../postclone.out',
            repo.path, dest])
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'master', ['master'])
     assert len(cloned.get_commits()) == 1
     self.check_hook_vars('../postclone', ["GBP_GIT_DIR"])
Esempio n. 7
0
    def test_clone_without_attrs(self, repo):
        """Test that cloning a repo without harmful attrs does nothing"""
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])

        attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
        # file may be empty or absent
        self.assertFalse(
            os.path.exists(attrs_file) and os.path.getsize(attrs_file),
            "%s is non-empty" % attrs_file)
    def test_pristine_tar_commit_on_origin(self, repo):
        """Test that we can create tarball from 'origin/pristine-tar'"""

        assert_true(repo.has_branch('pristine-tar'),
                    "Pristine-tar branch must exist in origin")
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)

        os.chdir(cloned.path)
        assert_false(cloned.has_branch('pristine-tar'),
                     "Pristine-tar branch must not exist in clone")
        ret = export_orig(['arg0', '--pristine-tar'])
        ok_(ret == 0, "Exporting tarballs must not fail")
Esempio n. 9
0
 def test_clone_github(self):
     """Test that cloning from github urls works"""
     dest = os.path.join(self._tmpdir, 'cloned_repo')
     ret = clone(['arg0', "github:agx/git-buildpackage", dest])
     self.assertEquals(ret, 0)
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'master', ['master'])
Esempio n. 10
0
 def test_clone_vcsgit_ok(self):
     """Test that cloning from vcs-git urls works"""
     dest = os.path.join(self._tmpdir, 'cloned_repo')
     ret = clone(['arg0', "vcsgit:libvirt-glib", dest])
     self.assertEquals(ret, 0)
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'debian/sid',
                            ['debian/sid', 'upstream/latest'])
Esempio n. 11
0
 def test_clone_vcsgit_ok(self):
     """Test that cloning from vcs-git urls works"""
     dest = os.path.join(self._tmpdir,
                         'cloned_repo')
     ret = clone(['arg0', "vcsgit:libvirt-glib", dest])
     self.assertEquals(ret, 0)
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'debian/sid', ['debian/sid', 'upstream/latest'])
Esempio n. 12
0
 def test_clone_github(self):
     """Test that cloning from github urls works"""
     dest = os.path.join(self._tmpdir,
                         'cloned_repo')
     ret = clone(['arg0', "github:agx/git-buildpackage", dest])
     self.assertEquals(ret, 0)
     cloned = ComponentTestGitRepository(dest)
     self._check_repo_state(cloned, 'master', ['master'])
Esempio n. 13
0
 def test_clone_nonempty(self, repo):
     """Test that cloning into an existing dir fails"""
     os.chdir('..')
     ok_(clone(['arg0', repo.path]) == 1, "Cloning did no fail as expected")
     self._check_log(
         -2, "gbp:error: Git command failed: Error "
         "running git clone: fatal: destination path "
         "'git-buildpackage' already exists and is not "
         "an empty directory.")
Esempio n. 14
0
 def test_clone_nonempty(self, repo):
     """Test that cloning into an existing dir fails"""
     os.chdir('..')
     ok_(clone(['arg0', repo.path]) == 1,
         "Cloning did no fail as expected")
     self._check_log(-2,
                     "gbp:error: Git command failed: Error "
                     "running git clone: fatal: destination path "
                     "'git-buildpackage' already exists and is not "
                     "an empty directory.")
Esempio n. 15
0
    def test_setup_gitattrs(self, repo):
        """Test that setting up Git attributes manually works"""
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])

        attrs_file = os.path.join(dest, '.git', 'info', 'attributes')

        # file shouldn’t exist at this point yet
        self.assertFalse(
            os.path.exists(attrs_file) and os.path.getsize(attrs_file),
            "%s is non-empty" % attrs_file)

        os.chdir(cloned.path)
        setup_gitattributes(['arg0'])

        ok_(os.path.exists(attrs_file), "%s is missing" % attrs_file)

        with open(attrs_file) as f:
            attrs = sorted(f.read().splitlines())
        self.assertEquals(attrs, sorted_gitattrs)
Esempio n. 16
0
    def test_setup_gitattrs_do_nothing(self, repo):
        """Test that disabling all knows presets works and gives an error"""
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])

        attrs_file = os.path.join(dest, '.git', 'info', 'attributes')

        # file shouldn’t exist at this point yet
        self.assertFalse(
            os.path.exists(attrs_file) and os.path.getsize(attrs_file),
            "%s is non-empty" % attrs_file)

        os.chdir(cloned.path)
        setup_gitattributes(['arg0', '--no-dgit-defuse-attrs'])

        # file shouldn’t exist at this point yet
        self.assertFalse(
            os.path.exists(attrs_file) and os.path.getsize(attrs_file),
            "%s is non-empty" % attrs_file)

        self._check_log(-1, "gbp:error: Nothing to do, no settings to apply.")
Esempio n. 17
0
    def test_tracking(self, repo):
        """Test that --track-missing picks up missing branches"""
        dest = os.path.join(self._tmpdir, 'cloned_repo')
        clone(['arg0', repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        os.chdir(cloned.path)
        self._check_repo_state(cloned, 'master', ['master'])
        # Pull initially
        eq_(pull(['argv0']), 0)
        assert len(repo.get_commits()) == 1
        self._check_repo_state(cloned, 'master', ['master'])

        # Pick up missing branches (none exist yet)
        eq_(pull(['argv0', '--track-missing']), 0)
        assert len(repo.get_commits()) == 1
        self._check_repo_state(cloned, 'master', ['master'])

        # Pick up missing branches
        repo.create_branch('pristine-tar')
        repo.create_branch('upstream')
        eq_(pull(['argv0', '--track-missing', '--pristine-tar']), 0)
        assert len(repo.get_commits()) == 1
        self._check_repo_state(cloned, 'master', ['master', 'pristine-tar', 'upstream'])
Esempio n. 18
0
    def test_clone_native(self):
        """Test that cloning of debian native packages works"""
        def _dsc(version):
            return os.path.join(DEB_TEST_DATA_DIR,
                                'dsc-native',
                                'git-buildpackage_%s.dsc' % version)

        # Build up somethng we can clone from
        dsc = _dsc('0.4.14')
        assert import_dsc(['arg0', dsc]) == 0
        repo = ComponentTestGitRepository('git-buildpackage')
        self._check_repo_state(repo, 'master', ['master'])
        assert len(repo.get_commits()) == 1

        dest = os.path.join(self._tmpdir,
                            'cloned_repo')
        clone(['arg0',
               '--postclone=printenv > postclone.out',
               repo.path, dest])
        cloned = ComponentTestGitRepository(dest)
        self._check_repo_state(cloned, 'master', ['master'])
        assert len(cloned.get_commits()) == 1
        self.check_hook_vars('postclone', ["GBP_GIT_DIR"])
Esempio n. 19
0
    def test_clone_nonempty(self):
        """Test that cloning into an existing dir fails"""
        def _dsc(version):
            return os.path.join(DEB_TEST_DATA_DIR,
                                'dsc-native',
                                'git-buildpackage_%s.dsc' % version)

        # Build up somethng we can clone from
        dsc = _dsc('0.4.14')
        assert import_dsc(['arg0', dsc]) == 0
        repo = ComponentTestGitRepository('git-buildpackage')
        self._check_repo_state(repo, 'master', ['master'])
        assert len(repo.get_commits()) == 1

        ok_(clone(['arg0', repo.path]) == 1,
            "Cloning did no fail as expected")
        self._check_log(-2, "gbp:error: Git command failed: Error running git clone: fatal: destination path 'git-buildpackage' already exists and is not an empty directory.")
Esempio n. 20
0
 def test_clone_vcsgit_fail(self):
     """Test that cloning from vcs-git urls fails as expected"""
     ret = clone(['arg0', "vcsgit:doesnotexist"])
     self.assertEquals(ret, 1)
     self._check_log(
         -1, "gbp:error: Can't find a source package for 'doesnotexist'")
Esempio n. 21
0
 def test_clone_vcsgit_fail(self):
     """Test that cloning from vcs-git urls fails as expected"""
     ret = clone(['arg0', "vcsgit:doesnotexist"])
     self.assertEquals(ret, 1)
     self._check_log(-1, "gbp:error: Can't find any vcs-git URL for 'doesnotexist'")