diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 56185b6c0..809094bcd 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,6 +5,7 @@ - added: `--removed-from-remote` flag to `git machete slide-out` (contributed by @raylu) - added: `--title` flag to `git machete github create-pr` that allows for setting PR title explicitly (suggested by @mjgigli) - added: `--with-urls` flag to `git machete github anno-prs` and `machete.github.annotateWithUrls` git config key that allow for adding the URL of the PR to the annotations (contributed by @guyboltonking) +- added: `--yes` flag to `git machete github create-pr` so that the user isn't asked whether to push the branch (suggested by @mkondratek) - deprecated: `git machete clean` and `git machete github sync`; use `github checkout-prs --mine`, `delete-unmanaged` and `slide-out --removed-from-remote` instead - fixed: PR author is now always added to annotation if different from current user (contributed by @guyboltonking) diff --git a/completion/git-machete.completion.bash b/completion/git-machete.completion.bash index 564e12c5c..01385ab5b 100644 --- a/completion/git-machete.completion.bash +++ b/completion/git-machete.completion.bash @@ -22,7 +22,7 @@ _git_machete() { local discover_opts="-C --checked-out-since= -l --list-commits -r --roots= -y --yes" local fork_point_opts="--inferred --override-to= --override-to-inferred --override-to-parent --unset-override" local github_anno_prs_opts="--with-urls" - local github_create_pr_opts="--draft --title=" + local github_create_pr_opts="--draft --title= --yes" local github_checkout_prs_opts="--all --by= --mine" local github_retarget_pr_opts="-b --branch= --ignore-if-missing" local reapply_opts="-f --fork-point=" diff --git a/completion/git-machete.completion.zsh b/completion/git-machete.completion.zsh index 08685e4e3..7ed3c3296 100644 --- a/completion/git-machete.completion.zsh +++ b/completion/git-machete.completion.zsh @@ -273,6 +273,7 @@ __git_machete_github_subcommands() { _arguments \ '(--draft)'--draft'[Create the new PR as draft]' \ '(--title)'--title='[Set the title for new PR explicitly]' \ + '(--yes)'--yes'[Do not ask for confirmation whether to push the branch]' \ "${common_flags[@]}" ;; diff --git a/completion/git-machete.fish b/completion/git-machete.fish index 0455f5654..880066b0c 100644 --- a/completion/git-machete.fish +++ b/completion/git-machete.fish @@ -103,6 +103,7 @@ complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_ complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from checkout-prs; and not __fish_seen_subcommand_from --mine" -x -l mine -d 'Checkout open PRs for the current user associated with the GitHub token' complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --draft" -f -l draft -d 'Create the new PR as a draft' complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --title" -x -l title -d 'Set the title for new PR explicitly' +complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --yes" -f -l yes -d 'Do not ask for confirmation whether to push the branch' complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from retarget-pr; and not __fish_seen_subcommand_from --branch" -x -l branch -s b -a '(__machete_managed_branches)' -d 'Specify the branch for which the associated PR base will be set to its upstream (parent) branch' complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from retarget-pr; and not __fish_seen_subcommand_from --ignore-if-missing" -f -l ignore-if-missing -d 'Ignore errors and quietly terminate execution if there is no PR opened for current (or specified) branch' diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1 index 5f11c2400..e12386ef9 100644 --- a/docs/man/git-machete.1 +++ b/docs/man/git-machete.1 @@ -1091,7 +1091,7 @@ Checkout open PRs for the current user associated with the GitHub token. .sp \fB ... \fP Pull request numbers to checkout. .TP -.B \fBcreate\-pr [\-\-draft] [\-\-title=]\fP: +.B \fBcreate\-pr [\-\-draft] [\-\-title=<title>] [\-\-yes]\fP: Creates a PR for the current branch, using the upstream (parent) branch as the PR base. Once the PR is successfully created, annotates the current branch with the new PR\(aqs number. .sp @@ -1111,6 +1111,9 @@ Create the new PR as a draft. .TP .BI \-\-title\fB= <title> Set the PR title explicitly (the default is to use the first included commit\(aqs message as the title). +.TP +.B \-\-yes +Do not ask for confirmation whether to push the branch. .UNINDENT .TP .B \fBrestack\-pr\fP: diff --git a/docs/source/cli/github.rst b/docs/source/cli/github.rst index 0f0af11f6..4b41815e5 100644 --- a/docs/source/cli/github.rst +++ b/docs/source/cli/github.rst @@ -53,7 +53,7 @@ Creates, checks out and manages GitHub PRs while keeping them reflected in branc ``<PR-number-1> ... <PR-number-N>`` Pull request numbers to checkout. -``create-pr [--draft] [--title=<title>]``: +``create-pr [--draft] [--title=<title>] [--yes]``: Creates a PR for the current branch, using the upstream (parent) branch as the PR base. Once the PR is successfully created, annotates the current branch with the new PR's number. @@ -71,6 +71,8 @@ Creates, checks out and manages GitHub PRs while keeping them reflected in branc --title=<title> Set the PR title explicitly (the default is to use the first included commit's message as the title). + --yes Do not ask for confirmation whether to push the branch. + ``restack-pr``: Perform the following sequence of actions: 1. If the PR for the current branch is ready for review, it gets converted to a draft. diff --git a/git_machete/cli.py b/git_machete/cli.py index 9771bf362..81fd8f341 100644 --- a/git_machete/cli.py +++ b/git_machete/cli.py @@ -250,6 +250,7 @@ def create_cli_parser() -> argparse.ArgumentParser: github_parser.add_argument('--mine', action='store_true') github_parser.add_argument('--title') github_parser.add_argument('--with-urls', action='store_true') + github_parser.add_argument('--yes', action='store_true') go_parser = subparsers.add_parser( 'go', @@ -697,6 +698,8 @@ def print_completion_resource(name: str) -> None: raise MacheteException("`--title` option is only valid with `create-pr` subcommand.") if 'with_urls' in parsed_cli and github_subcommand != 'anno-prs': raise MacheteException("`--with-urls` option is only valid with `anno-prs` subcommand.") + if 'yes' in parsed_cli and github_subcommand != 'create-pr': + raise MacheteException("`--yes` option is only valid with `create-pr` subcommand.") if github_subcommand == "anno-prs": machete_client.sync_annotations_to_github_prs(include_urls=cli_opts.opt_with_urls) @@ -715,7 +718,8 @@ def print_completion_resource(name: str) -> None: head=current_branch, opt_draft=cli_opts.opt_draft, opt_onto=cli_opts.opt_onto, - opt_title=cli_opts.opt_title) + opt_title=cli_opts.opt_title, + opt_yes=cli_opts.opt_yes) elif github_subcommand == "restack-pr": machete_client.restack_github_pr() elif github_subcommand == "retarget-pr": diff --git a/git_machete/client.py b/git_machete/client.py index 6e47fbd77..aa8a21d15 100644 --- a/git_machete/client.py +++ b/git_machete/client.py @@ -2429,11 +2429,12 @@ def create_github_pr( head: LocalBranchShortName, opt_draft: bool, opt_onto: Optional[LocalBranchShortName], - opt_title: Optional[str] + opt_title: Optional[str], + opt_yes: bool ) -> None: # first make sure that head branch is synced with remote try: - self.__sync_before_creating_pr(opt_onto=opt_onto, opt_yes=False) + self.__sync_before_creating_pr(opt_onto=opt_onto, opt_yes=opt_yes) except InteractionStopped: return @@ -2456,7 +2457,7 @@ def create_github_pr( is_called_from_github=True, opt_push_tracked=False, opt_push_untracked=True, - opt_yes=False) + opt_yes=opt_yes) else: prs_for_base_branch = github_client.get_open_pull_requests_by_head(base) if len(prs_for_base_branch) >= 1: diff --git a/git_machete/generated_docs.py b/git_machete/generated_docs.py index c6bca4385..b25a53d28 100644 --- a/git_machete/generated_docs.py +++ b/git_machete/generated_docs.py @@ -612,7 +612,7 @@ `<PR-number-1> ... <PR-number-N>` Pull request numbers to checkout. - `create-pr [--draft] [--title=<title>]`: + `create-pr [--draft] [--title=<title>] [--yes]`: Creates a PR for the current branch, using the upstream (parent) branch as the PR base. Once the PR is successfully created, annotates the current branch with the new PR's number. @@ -634,6 +634,9 @@ Set the PR title explicitly (the default is to use the first included commit's message as the title). + <b>--yes</b> + Do not ask for confirmation whether to push the branch. + `restack-pr`: Perform the following sequence of actions: diff --git a/tests/completion_e2e/test_completion_e2e.py b/tests/completion_e2e/test_completion_e2e.py index 1c42ef02d..50bf34754 100644 --- a/tests/completion_e2e/test_completion_e2e.py +++ b/tests/completion_e2e/test_completion_e2e.py @@ -61,7 +61,7 @@ "git machete github checkout-prs -": "--all --by --debug -h --help --mine -v --verbose", "git machete github create-pr -": - "--debug --draft -h --help --title -v --verbose", + "--debug --draft -h --help --title -v --verbose --yes", "git machete github retarget-pr --": "--branch --debug --help --ignore-if-missing --verbose", "git machete github retarget-pr -b ": diff --git a/tests/test_github.py b/tests/test_github.py index 1727e8f0d..977f8a1a6 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -341,5 +341,9 @@ def test_github_invalid_flag_combinations(self) -> None: "--ignore-if-missing option is only valid with retarget-pr subcommand.") assert_failure(["github", "checkout-prs", "--all", "--mine"], "checkout-prs subcommand must take exactly one of the following options: --all, --by=..., --mine, pr-number(s)") + assert_failure(["github", "checkout-prs", "--title=foo"], + "--title option is only valid with create-pr subcommand.") assert_failure(["github", "restack-pr", "--with-urls"], "--with-urls option is only valid with anno-prs subcommand.") + assert_failure(["github", "restack-pr", "--yes"], + "--yes option is only valid with create-pr subcommand.") diff --git a/tests/test_github_create_pr.py b/tests/test_github_create_pr.py index aa334d171..fdd8eb2ee 100644 --- a/tests/test_github_create_pr.py +++ b/tests/test_github_create_pr.py @@ -298,7 +298,6 @@ def github_api_state_for_test_create_pr_missing_base_branch_on_remote() -> MockG ) def test_github_create_pr_missing_base_branch_on_remote(self, mocker: MockerFixture) -> None: - self.patch_symbol(mocker, 'builtins.input', mock_input_returning_y) self.patch_symbol(mocker, 'git_machete.github.OrganizationAndRepository.from_url', mock_from_url) self.patch_symbol(mocker, 'git_machete.github.GitHubToken.for_domain', mock_github_token_for_domain_none) self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen( @@ -327,11 +326,11 @@ def test_github_create_pr_missing_base_branch_on_remote(self, mocker: MockerFixt expected_msg = ("Fetching origin...\n" "Warn: Base branch for this PR (feature/api_handling) is not found on remote, pushing...\n" - "Push untracked branch feature/api_handling to origin? (y, Q)\n" + "Pushing untracked branch feature/api_handling to origin...\n" "Creating a PR from feature/api_exception_handling to feature/api_handling... OK, see www.github.com\n") self.repo_sandbox.set_git_config_key("machete.github.annotateWithUrls", "true") - assert_success(['github', 'create-pr'], expected_msg) + assert_success(['github', 'create-pr', '--yes'], expected_msg) assert_success( ['status'], """