Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bugfix branching support #45

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions git-flow-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -63,6 +63,10 @@ _git_flow ()
__git_flow_feature
return
;;
bugfix)
__git_flow_bugfix
return
;;
release)
__git_flow_release
return
Expand Down Expand Up @@ -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"
Expand Down
103 changes: 103 additions & 0 deletions git-flow-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -66,6 +67,10 @@ _git-flow ()
(feature)
__git-flow-feature
;;

(bugfix)
__git-flow-bugfix
;;
esac
;;
esac
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
38 changes: 35 additions & 3 deletions git.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'