From ca32eda44c78f1657c4579e15e71d60d9540d8eb Mon Sep 17 00:00:00 2001 From: Rudinei Goi Roecker Date: Tue, 29 Mar 2016 08:50:51 -0300 Subject: [PATCH] Add bugfix branching support --- git-flow-completion.bash | 42 ++++++++++++++-- git-flow-completion.zsh | 103 +++++++++++++++++++++++++++++++++++++++ git.fish | 38 +++++++++++++-- 3 files changed, 177 insertions(+), 6 deletions(-) diff --git a/git-flow-completion.bash b/git-flow-completion.bash index 6ee517a..e260531 100755 --- a/git-flow-completion.bash +++ b/git-flow-completion.bash @@ -8,8 +8,8 @@ # The contained completion routines provide support for completing: # # * git-flow init and version -# * feature, hotfix and release branches -# * remote feature, hotfix and release branch names +# * feature, bugfix, hotfix and release branches +# * remote feature, bugfix, hotfix and release branch names # # # Installation @@ -47,7 +47,7 @@ _git_flow () { - local subcommands="init feature release hotfix support help version" + local subcommands="init feature bugfix release hotfix support help version" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" @@ -63,6 +63,10 @@ _git_flow () __git_flow_feature return ;; + bugfix) + __git_flow_bugfix + return + ;; release) __git_flow_release return @@ -123,6 +127,38 @@ __git_flow_feature () esac } +__git_flow_bugfix () +{ + local subcommands="list start finish publish track diff rebase checkout pull help" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + return + fi + + case "$subcommand" in + pull) + __gitcomp "$(__git_remotes)" + return + ;; + checkout|finish|diff|rebase) + __gitcomp "$(__git_flow_list_branches 'bugfix')" + return + ;; + publish) + __gitcomp "$(comm -23 <(__git_flow_list_branches 'bugfix') <(__git_flow_list_remote_branches 'bugfix'))" + return + ;; + track) + __gitcomp "$(comm -23 <(__git_flow_list_remote_branches 'bugfix') <(__git_flow_list_branches 'bugfix'))" + return + ;; + *) + COMPREPLY=() + ;; + esac +} + __git_flow_release () { local subcommands="list start finish track publish help" diff --git a/git-flow-completion.zsh b/git-flow-completion.zsh index 8607b5f..ec5c25f 100644 --- a/git-flow-completion.zsh +++ b/git-flow-completion.zsh @@ -36,6 +36,7 @@ _git-flow () subcommands=( 'init:Initialize a new git repo with support for the branching model.' 'feature:Manage your feature branches.' + 'bugfix:Manage your bugfix branches.' 'release:Manage your release branches.' 'hotfix:Manage your hotfix branches.' 'support:Manage your support branches.' @@ -66,6 +67,10 @@ _git-flow () (feature) __git-flow-feature ;; + + (bugfix) + __git-flow-bugfix + ;; esac ;; esac @@ -273,6 +278,93 @@ __git-flow-feature () esac } +__git-flow-bugfix () +{ + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '*::options:->options' + + case $state in + (command) + + local -a subcommands + subcommands=( + 'start:Start a new bugfix branch.' + 'finish:Finish a bugfix branch.' + 'list:List all your bugfix branches. (Alias to `git flow bugfix`)' + 'publish:Publish bugfix branch to remote.' + 'track:Checkout remote bugfix branch.' + 'diff:Show all changes.' + 'rebase:Rebase from integration branch.' + 'checkout:Checkout local bugfix branch.' + 'pull:Pull changes from remote.' + ) + _describe -t commands 'git flow bugfix' subcommands + _arguments \ + -v'[Verbose (more) output]' + ;; + + (options) + case $line[1] in + + (start) + _arguments \ + -F'[Fetch from origin before performing finish]'\ + ':bugfix:__git_flow_bugfix_list'\ + ':branch-name:__git_branch_names' + ;; + + (finish) + _arguments \ + -F'[Fetch from origin before performing finish]' \ + -r'[Rebase instead of merge]'\ + ':bugfix:__git_flow_bugfix_list' + ;; + + (publish) + _arguments \ + ':bugfix:__git_flow_bugfix_list'\ + ;; + + (track) + _arguments \ + ':bugfix:__git_flow_bugfix_list'\ + ;; + + (diff) + _arguments \ + ':branch:__git_branch_names'\ + ;; + + (rebase) + _arguments \ + -i'[Do an interactive rebase]' \ + ':branch:__git_branch_names' + ;; + + (checkout) + _arguments \ + ':branch:__git_flow_bugfix_list'\ + ;; + + (pull) + _arguments \ + ':remote:__git_remotes'\ + ':branch:__git_branch_names' + ;; + + *) + _arguments \ + -v'[Verbose (more) output]' + ;; + esac + ;; + esac +} + __git_flow_version_list () { local expl @@ -295,6 +387,17 @@ __git_flow_feature_list () _wanted features expl 'feature' compadd $features } +__git_flow_bugfix_list () +{ + local expl + declare -a bugfixes + + bugfixes=(${${(f)"$(_call_program bugfixes git flow bugfix list 2> /dev/null | tr -d ' |*')"}}) + __git_command_successful || return + + _wanted bugfixes expl 'bugfix' compadd $bugfixes +} + __git_remotes () { local expl gitdir remotes diff --git a/git.fish b/git.fish index 2cf6c68..26e1f17 100644 --- a/git.fish +++ b/git.fish @@ -8,8 +8,8 @@ # The contained completion routines provide support for completing: # # * git-flow init and version -# * feature, hotfix and release branches -# * remote feature, hotfix and release branch names +# * feature, bugfix, hotfix and release branches +# * remote feature, bugfix, hotfix and release branch names # # # Installation @@ -137,6 +137,39 @@ complete -f -c git -n '__fish_git_flow_using_command feature pull' -a '(__fish_g +## git-flow bugfix + +complete -f -c git -n '__fish_git_flow_using_command' -a bugfix -d 'Manage bugfix branches' +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a list -d 'List bugfix branches' +complete -f -c git -n '__fish_git_flow_using_command bugfix' -s v -d 'Verbose output' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a start -d 'Start a new bugfix branch' +complete -f -c git -n '__fish_git_flow_using_command bugfix start' -s F -d 'Fetch from origin first' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a finish -d 'Finish a bugfix branch' +complete -f -c git -n '__fish_git_flow_using_command bugfix finish' -s F -d 'Fetch from origin first' +complete -f -c git -n '__fish_git_flow_using_command bugfix finish' -s r -d 'Rebase instead of merging' +complete -f -c git -n '__fish_git_flow_using_command bugfix finish' -a '(__fish_git_flow_branches bugfix)' -d 'Bugfix branch' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a publish -d 'Publish a bugfix branch to remote' +complete -f -c git -n '__fish_git_flow_using_command bugfix publish' -a '(__fish_git_flow_unpublished_branches bugfix)' -d 'Bugfix branch' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a track -d 'Checkout remote bugfix branch' +complete -f -c git -n '__fish_git_flow_using_command bugfix track' -a '(__fish_git_flow_untracked_branches bugfix)' -d 'Bugfix branch' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a diff -d 'Show all changes' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a rebase -d 'Rebase against integration branch' +complete -f -c git -n '__fish_git_flow_using_command bugfix rebase' -s i -d 'Do an interactive rebase' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a checkout -d 'Checkout local bugfix branch' +complete -f -c git -n '__fish_git_flow_using_command bugfix checkout' -a '(__fish_git_flow_branches bugfix)' -d 'Bugfix branch' + +complete -f -c git -n '__fish_git_flow_using_command bugfix' -a pull -d 'Pull changes from remote' +complete -f -c git -n '__fish_git_flow_using_command bugfix pull' -a '(__fish_git_remotes)' -d 'Remote' + + + ## git-flow release complete -f -c git -n '__fish_git_flow_using_command' -a release -d 'Manage release branches' @@ -189,4 +222,3 @@ complete -f -c git -n '__fish_git_flow_using_command support' -s v -d 'Verbos complete -f -c git -n '__fish_git_flow_using_command support' -a start -d 'Start a new support branch' complete -f -c git -n '__fish_git_flow_using_command support start' -s F -d 'Fetch from origin first' -