Esempio n. 1
0
    def test_pull_tag(self):
        git = sources.Git('git://my-source', 'source_dir', source_tag='tag')
        git.pull()

        self.mock_run.assert_called_once_with(
            ['git', 'clone', '--depth', '1', '--recursive', '--branch', 'tag',
             'git://my-source', 'source_dir'])
Esempio n. 2
0
    def test_pull_existing_with_branch(self):
        self.mock_path_exists.return_value = True

        git = sources.Git("git://my-source",
                          "source_dir",
                          source_branch="my-branch")
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call([
                "git",
                "-C",
                "source_dir",
                "fetch",
                "--prune",
                "--recurse-submodules=yes",
            ]),
            mock.call([
                "git",
                "-C",
                "source_dir",
                "reset",
                "--hard",
                "refs/heads/my-branch",
            ]),
            mock.call([
                "git",
                "-C",
                "source_dir",
                "submodule",
                "update",
                "--recursive",
                "--force",
            ]),
        ])
Esempio n. 3
0
    def test_pull_commit(self):
        git = sources.Git(
            "git://my-source",
            "source_dir",
            source_commit="2514f9533ec9b45d07883e10a561b248497a8e3c",
        )
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call([
                "git", "clone", "--recursive", "git://my-source", "source_dir"
            ]),
            mock.call([
                "git",
                "-C",
                "source_dir",
                "fetch",
                "origin",
                "2514f9533ec9b45d07883e10a561b248497a8e3c",
            ]),
            mock.call([
                "git",
                "-C",
                "source_dir",
                "checkout",
                "2514f9533ec9b45d07883e10a561b248497a8e3c",
            ]),
        ])
Esempio n. 4
0
    def setUp(self):
        super().setUp()
        self.working_tree = 'git-test'
        self.source_dir = 'git-checkout'
        self.clean_dir(self.working_tree)
        os.chdir(self.working_tree)
        self.call(['git', 'init'])
        self.call(['git', 'config', '--local', 'user.name', '"Example Dev"'])
        self.call(
            ['git', 'config', '--local', 'user.email', '*****@*****.**'])
        with open('testing', 'w') as fp:
            fp.write('testing')
        self.call(['git', 'add', 'testing'])
        self.call(['git', 'commit', '-am', 'testing'])
        self.call(['git', 'tag', 'test-tag'])
        self.expected_commit = self.call_with_output(['git', 'log']).split()[1]
        self.expected_branch = self.call_with_output(
            ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
        self.expected_tag = 'test-tag'

        os.chdir('..')

        self.git = sources.Git(self.working_tree, self.source_dir, silent=True)
        self.git.pull()

        self.source_details = self.git._get_source_details()
Esempio n. 5
0
    def test_pull_existing_with_submodules(self):
        self.mock_path_exists.return_value = True

        git = sources.Git(
            "git://my-source",
            "source_dir",
            source_submodules=["submodule_1", "dir/submodule_2"],
        )
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call([
                "git",
                "-C",
                "source_dir",
                "fetch",
                "--prune",
                "--recurse-submodules=yes",
            ]),
            mock.call([
                "git", "-C", "source_dir", "reset", "--hard", "origin/master"
            ]),
            mock.call([
                "git",
                "-C",
                "source_dir",
                "submodule",
                "update",
                "--recursive",
                "--force",
                "submodule_1",
                "dir/submodule_2",
            ]),
        ])
Esempio n. 6
0
    def test_pull(self):
        git = sources.Git("git://my-source", "source_dir")

        git.pull()

        self.mock_run.assert_called_once_with(
            ["git", "clone", "--recursive", "git://my-source", "source_dir"])
Esempio n. 7
0
    def test_pull(self):
        git = sources.Git('git://my-source', 'source_dir')

        git.pull()

        self.mock_run.assert_called_once_with(
            ['git', 'clone', '--recursive', 'git://my-source', 'source_dir'])
Esempio n. 8
0
    def test_add(self):
        url = "git://my-source"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        git.add("file")
        self.mock_run.assert_called_once_with(
            ["git", "-C", "source_dir", "add", "file"])
Esempio n. 9
0
    def test_init_with_source_branch_and_tag_raises_exception(self):
        with self.assertRaises(sources.IncompatibleOptionsError) as raised:
            sources.Git('git://mysource', 'source_dir',
                        source_tag='tag', source_branch='branch')

        expected_message = \
            'can\'t specify both source-tag and source-branch for a git source'
        self.assertEqual(raised.exception.message, expected_message)
Esempio n. 10
0
    def test_git_details_tag(self):
        self.git = sources.Git(
            self.working_tree, self.source_dir, silent=True, source_tag="test-tag"
        )
        self.git.pull()

        self.source_details = self.git._get_source_details()
        self.assertThat(self.source_details["source-tag"], Equals(self.expected_tag))
Esempio n. 11
0
    def test_add_abs_path(self):
        url = "git://my-source"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        git.add(os.path.join(source_dir, "file"))
        self.fake_check_output.assert_called_once_with(
            ["git", "-C", "source_dir", "add", "file"])
Esempio n. 12
0
    def test_init(self):
        url = "git://my-source"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        git.init()
        self.fake_check_output.assert_called_once_with(
            ["git", "-C", "source_dir", "init"])
Esempio n. 13
0
    def test_git_details_tag(self):
        self.git = sources.Git(self.working_tree,
                               self.source_dir,
                               silent=True,
                               source_tag='test-tag')
        self.git.pull()

        self.source_details = self.git._get_source_details()
        self.assertEqual(self.expected_tag, self.source_details['tag'])
Esempio n. 14
0
    def test_pull_failure(self):
        self.mock_run.side_effect = subprocess.CalledProcessError(1, [])

        git = sources.Git("git://my-source", "source_dir")
        raised = self.assertRaises(sources.errors.SnapcraftPullError, git.pull)
        self.assertThat(
            raised.command,
            Equals("git clone --recursive git://my-source source_dir"))
        self.assertThat(raised.exit_code, Equals(1))
Esempio n. 15
0
    def test_git_details_branch(self):
        shutil.rmtree(self.source_dir)
        self.git = sources.Git(self.working_tree, self.source_dir, silent=True,
                               source_branch=self.expected_branch)
        self.git.pull()

        self.source_details = self.git._get_source_details()
        self.assertThat(
            self.source_details['source-branch'], Equals(self.expected_branch))
Esempio n. 16
0
    def test_push(self):
        url = "git://my-source"
        refspec = "HEAD:master"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        git.push(url, refspec)
        self.mock_run.assert_called_once_with(
            ["git", "-C", "source_dir", "push", url, refspec])
Esempio n. 17
0
    def test_pull_with_submodules_empty(self):
        git = sources.Git("git://my-source",
                          "source_dir",
                          source_submodules=[])

        git.pull()

        self.mock_run.assert_called_once_with(
            ["git", "clone", "git://my-source", "source_dir"])
Esempio n. 18
0
    def test_push_force(self):
        url = "git://my-source"
        refspec = "HEAD:master"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        git.push(url, refspec, force=True)
        self.fake_check_output.assert_called_once_with(
            ["git", "-C", "source_dir", "push", url, refspec, "--force"])
Esempio n. 19
0
    def test_init_with_source_tag_and_commit_raises_exception(self):
        with self.assertRaises(sources.IncompatibleOptionsError) as raised:
            sources.Git(
                'git://mysource', 'source_dir',
                source_commit='2514f9533ec9b45d07883e10a561b248497a8e3c',
                source_tag='tag')

        expected_message = \
            'can\'t specify both source-tag and source-commit for ' \
            'a git source'
        self.assertEqual(raised.exception.message, expected_message)
Esempio n. 20
0
    def test_init_error(self):
        self.fake_check_output.side_effect = fake_git_command_error
        url = "git://my-source"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)

        error = self.assertRaises(errors.GitCommandError, git.init)
        self.assertThat(
            error.get_brief(),
            Equals("Failed to execute git command: git -C source_dir init"),
        )
Esempio n. 21
0
    def test_pull_commit(self):
        git = sources.Git(
            'git://my-source', 'source_dir',
            source_commit='2514f9533ec9b45d07883e10a561b248497a8e3c')
        git.pull()

        self.mock_run.assert_has_calls([
            unittest.mock.call(['git', 'clone', '--recursive',
                                'git://my-source', 'source_dir']),
            unittest.mock.call(['git', '-C', 'source_dir', 'checkout',
                                '2514f9533ec9b45d07883e10a561b248497a8e3c'])
        ])
Esempio n. 22
0
    def test_pull_tag(self):
        git = sources.Git("git://my-source", "source_dir", source_tag="tag")
        git.pull()

        self.mock_run.assert_called_once_with([
            "git",
            "clone",
            "--recursive",
            "--branch",
            "tag",
            "git://my-source",
            "source_dir",
        ])
Esempio n. 23
0
    def test_pull_existing(self):
        self.mock_path_exists.return_value = True

        git = sources.Git('git://my-source', 'source_dir')
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call([
                'git', '-C', 'source_dir', 'pull', '--recurse-submodules=yes',
                'git://my-source', 'HEAD'
            ]),
            mock.call(['git', '-C', 'source_dir', 'submodule', 'update'])
        ])
Esempio n. 24
0
    def test_pull_existing_with_tag(self):
        self.mock_path_exists.return_value = True

        git = sources.Git('git://my-source', 'source_dir', source_tag='tag')
        git.pull()

        self.mock_run.assert_has_calls([
            unittest.mock.call(['git', '-C', 'source_dir', 'pull',
                                '--recurse-submodules=yes', 'git://my-source',
                                'refs/tags/tag']),
            unittest.mock.call(['git', '-C', 'source_dir', 'submodule',
                                'update'])
        ])
Esempio n. 25
0
    def test_pull_with_depth(self):
        git = sources.Git("git://my-source", "source_dir", source_depth=2)

        git.pull()

        self.mock_run.assert_called_once_with([
            "git",
            "clone",
            "--recursive",
            "--depth",
            "2",
            "git://my-source",
            "source_dir",
        ])
Esempio n. 26
0
    def test_pull_existing_with_submodules_empty(self):
        self.mock_path_exists.return_value = True

        git = sources.Git("git://my-source",
                          "source_dir",
                          source_submodules=[])
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call(["git", "-C", "source_dir", "fetch", "--prune"]),
            mock.call([
                "git", "-C", "source_dir", "reset", "--hard", "origin/master"
            ]),
        ])
Esempio n. 27
0
    def test_push_error(self):
        self.fake_check_output.side_effect = fake_git_command_error
        url = "git://my-source"
        refspec = "HEAD:master"
        source_dir = "source_dir"

        git = sources.Git(url, source_dir)
        error = self.assertRaises(errors.GitCommandError, git.push, url, refspec)
        self.assertThat(
            error.get_brief(),
            Equals(
                "Failed to execute git command: git -C source_dir push git://my-source HEAD:master"
            ),
        )
Esempio n. 28
0
    def test_pull_existing(self):
        self.mock_path_exists.return_value = True

        git = sources.Git('git://my-source', 'source_dir')
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call(['git', '-C', 'source_dir', 'fetch',
                       '--prune', '--recurse-submodules=yes']),
            mock.call(['git', '-C', 'source_dir', 'reset', '--hard',
                       'origin/master']),
            mock.call(['git', '-C', 'source_dir', 'submodule', 'update',
                       '--recursive', '--remote'])
        ])
Esempio n. 29
0
    def test_pull_existing_with_branch(self):
        self.mock_path_exists.return_value = True

        git = sources.Git('git://my-source', 'source_dir',
                          source_branch='my-branch')
        git.pull()

        self.mock_run.assert_has_calls([
            mock.call(['git', '-C', 'source_dir', 'fetch', '--prune',
                       '--recurse-submodules=yes']),
            mock.call(['git', '-C', 'source_dir', 'reset', '--hard',
                       'refs/heads/my-branch']),
            mock.call(['git', '-C', 'source_dir', 'submodule', 'update',
                       '--recursive', '--force'])
        ])
Esempio n. 30
0
    def test_pull_existing_with_commit(self):
        self.mock_path_exists.return_value = True

        git = sources.Git(
            'git://my-source', 'source_dir',
            source_commit='2514f9533ec9b45d07883e10a561b248497a8e3c')
        git.pull()

        self.mock_run.assert_has_calls([
            unittest.mock.call(['git', '-C', 'source_dir', 'pull',
                                '--recurse-submodules=yes', 'git://my-source',
                                '2514f9533ec9b45d07883e10a561b248497a8e3c']),
            unittest.mock.call(['git', '-C', 'source_dir', 'submodule',
                                'update'])
        ])