Skip to content

Commit

Permalink
Add -H/--sync-github-prs and -L/--sync-gitlab-mrs flags to `t…
Browse files Browse the repository at this point in the history
…raverse`
  • Loading branch information
PawelLipski committed Oct 14, 2024
1 parent 8f48107 commit d07fbad
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 60 deletions.
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release notes

## New in git-machete 3.30.1
## New in git-machete 3.31.0

- added: flags `-H`/`--sync-github-prs` and `-L`/`--sync-gitlab-mrs` to `traverse` to automatically retarget PRs/MRs when traversing (suggested by @chriscz)

## New in git-machete 3.30.0

Expand Down
4 changes: 2 additions & 2 deletions completion/git-machete.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _git_machete() {
local common_opts="--debug -h --help -v --verbose"
local add_opts="-f --as-first-child -o --onto= -R --as-root -y --yes"
local advance_opts="-y --yes"
local anno_opts="-b --branch= -H -L --sync-github-prs --sync-gitlab-mrs"
local anno_opts="-b --branch= -H --sync-github-prs -L --sync-gitlab-mrs"
local delete_unmanaged_opts="-y --yes"
local diff_opts="-s --stat"
local discover_opts="-C --checked-out-since= -l --list-commits -r --roots= -y --yes"
Expand All @@ -34,7 +34,7 @@ _git_machete() {
local slide_out_opts="-d --down-fork-point= --delete -M --merge -n --no-edit-merge --no-interactive-rebase --removed-from-remote"
local squash_opts="-f --fork-point="
local status_opts="--color= -L --list-commits-with-hashes -l --list-commits --no-detect-squash-merges"
local traverse_opts="-F --fetch -l --list-commits -M --merge -n --no-detect-squash-merges --no-edit-merge --no-interactive-rebase --no-push --no-push-untracked --push --push-untracked --return-to= --start-from= -w --whole -W -y --yes"
local traverse_opts="-F --fetch -H --sync-github-prs -L --sync-gitlab-mrs -l --list-commits -M --merge -n --no-detect-squash-merges --no-edit-merge --no-interactive-rebase --no-push --no-push-untracked --push --push-untracked --return-to= --start-from= -w --whole -W -y --yes"
local update_opts="-f --fork-point= -M --merge -n --no-edit-merge --no-interactive-rebase"

cur=${COMP_WORDS[$COMP_CWORD]}
Expand Down
2 changes: 2 additions & 0 deletions completion/git-machete.completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ _git-machete() {
(t|traverse)
_arguments \
'(-F --fetch)'{-F,--fetch}'[Fetch the remotes of all managed branches at the beginning of traversal]' \
'(-H --sync-github-prs)'{-H,--sync-github-prs}'[Retarget GitHub PR when its base branch is different than in machete file]' \
'(-L --sync-gitlab-mrs)'{-L,--sync-gitlab-mrs}'[Retarget GitLab MR when its target branch is different than in machete file]' \
'(-l --list-commits)'{-l,--list-commits}'[List the messages of commits introduced on each branch]' \
'(-M --merge)'{-M,--merge}'[Update by merge rather than by rebase]' \
'(-n)'-n'[If updating by rebase, equivalent to --no-interactive-rebase. If updating by merge, equivalent to --no-edit-merge]' \
Expand Down
34 changes: 18 additions & 16 deletions completion/git-machete.fish
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,24 @@ complete -c git-machete -n "__fish_seen_subcommand_from status s; and not __fish

# git machete traverse
complete -c git-machete -n "not __fish_seen_subcommand_from $__machete_commands" -f -a traverse -d 'Walk through the tree of branch dependencies and rebase, merge, slide out, push and/or pull each branch one by one'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --fetch -F" -f -l fetch -s F -d 'Fetch the remotes of all managed branches at the beginning of traversal (no git pull involved, only git fetch)'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --list-commits -l" -f -l list-commits -s l -d 'When printing the status, additionally list the messages of commits introduced on each branch'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --merge -M" -f -l merge -s M -d 'Update by merge rather than by rebase'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --yes -y" -f -s n -d 'If updating by rebase, equivalent to --no-interactive-rebase. If updating by merge, equivalent to --no-edit-merge'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-detect-squash-merges" -f -l no-detect-squash-merges -d 'Only consider "strict" (fast-forward or 2-parent) merges, rather than rebase/squash merges, when detecting if a branch is merged into its upstream (parent)'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-edit-merge" -f -l no-edit-merge -d 'If updating by merge, skip opening the editor for merge commit message while doing git merge (i.e. pass --no-edit flag to underlying git merge). Not allowed if updating by rebase'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-interactive-rebase" -f -l no-interactive-rebase -d 'If updating by rebase, run git rebase in non-interactive mode (without -i/--interactive flag). Not allowed if updating by merge'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-push" -f -l no-push -d 'Do not push any (neither tracked nor untracked) branches to remote, re-enable via --push'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-push-untracked" -f -l no-push-untracked -d 'Do not push untracked branches to remote, re-enable via --push-untracked'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --push" -f -l push -d 'Push all (both tracked and untracked) branches to remote - default behavior'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --push-untracked" -f -l push-untracked -d 'Push untracked branches to remote - default behavior'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --return-to" -x -l return-to -a 'stay here nearest-remaining' -d 'Specifies the branch to return after traversal is successfully completed'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --start-from" -x -l start-from -a 'here root first-root' -d 'Specifies the branch to start the traversal from'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --whole -w" -f -l whole -s w -d 'Equivalent to -n --start-from=first-root --return-to=nearest-remaining'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from -W" -f -s W -d 'Equivalent to --fetch --whole; useful for even more automated traversal of all branches'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --yes -y" -f -l yes -s y -d 'Do not ask for any interactive input, including confirmation of rebase/push/pull. Implies -n'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --fetch -F" -f -l fetch -s F -d 'Fetch the remotes of all managed branches at the beginning of traversal (no git pull involved, only git fetch)'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --list-commits -l" -f -l list-commits -s l -d 'When printing the status, additionally list the messages of commits introduced on each branch'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --sync-gitlab-mrs" -f -l sync-github-prs -s H -d 'Retarget GitHub PR when its base branch is different than in machete file'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --sync-github-prs" -f -l sync-gitlab-mrs -s L -d 'Retarget GitLab MR when its target branch is different than in machete file'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --merge -M" -f -l merge -s M -d 'Update by merge rather than by rebase'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --yes -y" -f -s n -d 'If updating by rebase, equivalent to --no-interactive-rebase. If updating by merge, equivalent to --no-edit-merge'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-detect-squash-merges" -f -l no-detect-squash-merges -d 'Only consider "strict" (fast-forward or 2-parent) merges, rather than rebase/squash merges, when detecting if a branch is merged into its upstream (parent)'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-edit-merge" -f -l no-edit-merge -d 'If updating by merge, skip opening the editor for merge commit message while doing git merge (i.e. pass --no-edit flag to underlying git merge). Not allowed if updating by rebase'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-interactive-rebase" -f -l no-interactive-rebase -d 'If updating by rebase, run git rebase in non-interactive mode (without -i/--interactive flag). Not allowed if updating by merge'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-push" -f -l no-push -d 'Do not push any (neither tracked nor untracked) branches to remote, re-enable via --push'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --no-push-untracked" -f -l no-push-untracked -d 'Do not push untracked branches to remote, re-enable via --push-untracked'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --push" -f -l push -d 'Push all (both tracked and untracked) branches to remote - default behavior'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --push-untracked" -f -l push-untracked -d 'Push untracked branches to remote - default behavior'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --return-to" -x -l return-to -a 'stay here nearest-remaining' -d 'Specifies the branch to return after traversal is successfully completed'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --start-from" -x -l start-from -a 'here root first-root' -d 'Specifies the branch to start the traversal from'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --whole -w" -f -l whole -s w -d 'Equivalent to -n --start-from=first-root --return-to=nearest-remaining'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from -W" -f -s W -d 'Equivalent to --fetch --whole; useful for even more automated traversal of all branches'
complete -c git-machete -n "__fish_seen_subcommand_from traverse t; and not __fish_seen_subcommand_from --yes -y" -f -l yes -s y -d 'Do not ask for any interactive input, including confirmation of rebase/push/pull. Implies -n'

# git machete update
complete -c git-machete -n "not __fish_seen_subcommand_from $__machete_commands" -f -a update -d 'Sync the current branch with its upstream (parent) branch via rebase or merge'
Expand Down
12 changes: 12 additions & 0 deletions docs/source/cli/traverse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ traverse
git machete t[raverse] [-F|--fetch] [-l|--list-commits] [-M|--merge]
[-n|--no-edit-merge|--no-interactive-rebase] [--[no-]push] [--[no-]push-untracked]
[--return-to=WHERE] [--start-from=WHERE] [--squash-merge-detection=MODE]
[-H|--sync-github-prs|-L|--sync-gitlab-mrs]
[-w|--whole] [-W] [-y|--yes]
Traverses the branches in the order as they occur in branch layout file.
Expand Down Expand Up @@ -52,6 +53,11 @@ For each branch, the command:

- asks the user whether to **pull** the branch;

* if ``-H``/``--sync-github-prs`` or ``-L``/``--sync-gitlab-mrs`` option is present:

- retargets the PR/MR if it exists for the given branch and has a different base/target branch in GitHub/GitLab than the upstream in machete file,
just as ``git machete github retarget-pr`` and ``git machete gitlab retarget-mr`` would do;

* and finally, if any of the above operations has been successfully completed:

- prints the updated ``status``.
Expand Down Expand Up @@ -88,6 +94,12 @@ when the current user is NOT the author of the PR/MR associated with that branch

-F, --fetch Fetch the remotes of all managed branches at the beginning of traversal (no ``git pull`` involved, only ``git fetch``).

-H, --sync-github-prs Retarget the PR if it exists for the given branch and has a different base branch in GitHub than the upstream in machete file,
just as ``git machete github retarget-pr`` would do

-L, --sync-gitlab-mrs Retarget the MR if it exists for the given branch and has a different target branch in GitLab than the upstream in machete file,
just as ``git machete gitlab retarget-mr`` would do

-l, --list-commits When printing the status, additionally list the messages of commits introduced on each branch.

-M, --merge Update by merge rather than by rebase.
Expand Down
2 changes: 1 addition & 1 deletion git_machete/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.30.1'
__version__ = '3.31.0'
14 changes: 9 additions & 5 deletions git_machete/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,23 @@ def add_code_hosting_parser(command: str, subcommand_suffix: str, include_sync:
add_help=False,
parents=[common_args_parser])
traverse_parser.add_argument('-F', '--fetch', action='store_true')
traverse_parser.add_argument('-H', '--sync-github-prs', action='store_true')
traverse_parser.add_argument('-l', '--list-commits', action='store_true')
traverse_parser.add_argument('-L', '--sync-gitlab-mrs', action='store_true')
traverse_parser.add_argument('-M', '--merge', action='store_true')
traverse_parser.add_argument('-n', action='store_true')
traverse_parser.add_argument('--no-detect-squash-merges', action='store_true')
traverse_parser.add_argument('--no-edit-merge', action='store_true')
traverse_parser.add_argument('--no-interactive-rebase', action='store_true')
traverse_parser.add_argument('--no-detect-squash-merges', action='store_true')
traverse_parser.add_argument('--squash-merge-detection')
traverse_parser.add_argument('--push', action='store_true')
traverse_parser.add_argument('--no-push', action='store_true')
traverse_parser.add_argument('--push-untracked', action='store_true')
traverse_parser.add_argument('--no-push-untracked', action='store_true')
traverse_parser.add_argument('--push', action='store_true')
traverse_parser.add_argument('--push-untracked', action='store_true')
traverse_parser.add_argument('--return-to')
traverse_parser.add_argument('--squash-merge-detection')
traverse_parser.add_argument('--start-from')
traverse_parser.add_argument('-w', '--whole', action='store_true')
traverse_parser.add_argument('-W', action='store_true')
traverse_parser.add_argument('-w', '--whole', action='store_true')
traverse_parser.add_argument('-y', '--yes', action='store_true')

update_parser = subparsers.add_parser(
Expand Down Expand Up @@ -921,6 +923,8 @@ def strip_remote_name(remote_branch: RemoteBranchShortName) -> LocalBranchShortN
opt_return_to=opt_return_to,
opt_squash_merge_detection=opt_squash_merge_detection,
opt_start_from=opt_start_from,
opt_sync_github_prs=cli_opts.opt_sync_github_prs,
opt_sync_gitlab_mrs=cli_opts.opt_sync_gitlab_mrs,
opt_yes=cli_opts.opt_yes)
elif cmd == "update":
machete_client.read_branch_layout_file(perform_interactive_slide_out=should_perform_interactive_slide_out)
Expand Down
Loading

0 comments on commit d07fbad

Please sign in to comment.