Beispiel #1
0
def test_not_on_any_branch(test_repo: Path, test_git_bumper: GitBumper) -> None:
    tbump.git.run_git(test_repo, "commit", "--message", "test", "--allow-empty")
    tbump.git.run_git(test_repo, "checkout", "HEAD~1")

    with pytest.raises(tbump.git_bumper.NotOnAnyBranch):
        test_git_bumper.check_dirty()
        test_git_bumper.check_branch_state("1.2.42")
def test_git_bumper_no_tracking_ref(test_repo: Path,
                                    test_git_bumper: GitBumper) -> None:
    tbump.git.run_git(test_repo, "checkout", "-b", "devel")

    with pytest.raises(tbump.git_bumper.NoTrackedBranch):
        test_git_bumper.check_dirty()
        test_git_bumper.check_branch_state("1.2.42")
Beispiel #3
0
def test_git_bumper_happy_path(test_repo: Path, test_git_bumper: GitBumper) -> None:
    new_version = "1.2.42"
    test_git_bumper.check_dirty()
    test_git_bumper.check_branch_state(new_version)
    # Make sure git add does not fail:
    # we could use file_bumper here instead
    (test_repo / "VERSION").write_text(new_version)
    commands = test_git_bumper.get_commands(new_version)
    for command in commands:
        command.run()
    _, out = tbump.git.run_git_captured(test_repo, "log", "--oneline")
    assert "Bump to %s" % new_version in out
Beispiel #4
0
    def add_git_and_hook_actions(
        self, new_version: str, git_bumper: GitBumper, hooks_runner: HooksRunner
    ) -> None:
        before_hooks = ActionGroup(
            "Would run these hooks before commit",
            "Running hooks before commit",
            hooks_runner.get_before_hooks(new_version),
            should_enumerate=True,
        )
        self.work.append(before_hooks)

        git_commands = ActionGroup(
            "Would run these git commands",
            "Making bump commit and push matching tag",
            git_bumper.get_commands(new_version),
        )
        self.work.append(git_commands)

        after_hooks = ActionGroup(
            "Would run these hooks after push",
            "Running hooks after push",
            hooks_runner.get_after_hooks(new_version),
            should_enumerate=True,
        )
        self.work.append(after_hooks)
Beispiel #5
0
def bump(options: BumpOptions) -> None:
    working_path = options.working_path
    new_version = options.new_version
    interactive = options.interactive
    only_patch = options.only_patch
    dry_run = options.dry_run

    config = parse_config(options.working_path)

    # fmt: off
    ui.info_1(
        "Bumping from",
        ui.bold,
        config.current_version,
        ui.reset,
        "to",
        ui.bold,
        new_version,
    )
    # fmt: on

    git_bumper = GitBumper(working_path)
    git_bumper.set_config(config)
    git_state_error = None
    try:
        git_bumper.check_dirty()  # Avoid data loss
        if not only_patch:
            git_bumper.check_branch_state(new_version)
    except tbump.git.GitError as e:
        if dry_run:
            git_state_error = e
        else:
            raise

    file_bumper = FileBumper(working_path)
    file_bumper.set_config(config)

    hooks_runner = HooksRunner(working_path, config.current_version)
    if not only_patch:
        for hook in config.hooks:
            hooks_runner.add_hook(hook)

    executor = Executor(new_version, file_bumper)
    if not only_patch:
        executor.add_git_and_hook_actions(new_version, git_bumper,
                                          hooks_runner)

    if interactive:
        executor.print_self(dry_run=True)
        if not dry_run:
            proceed = ui.ask_yes_no("Looking good?", default=False)
            if not proceed:
                raise Cancelled()

    if dry_run:
        if git_state_error:
            ui.error("Git repository state is invalid")
            git_state_error.print_error()
            sys.exit(1)
        else:
            return

    executor.print_self(dry_run=False)
    executor.run()

    if config.github_url:
        tag_name = git_bumper.get_tag_name(new_version)
        suggest_creating_github_release(config.github_url, tag_name)