3 #==============================================================================
5 # File ID: fe636b92-445c-11e4-940c-c80aa9e67bbd
7 # Create subbranches using '.' as level delimiter.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
23 while test -n "$1"; do
25 -D|
--delete) opt_delete
=1; shift ;;
26 -h|
--help) opt_help
=1; shift ;;
27 -m|
--merge) opt_merge
=1; shift ;;
28 -p|
--parent) opt_parent
=1; shift ;;
29 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
30 -s|
--squash) opt_squash
=1; shift ;;
31 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
32 --version) echo $progname $VERSION; exit 0 ;;
35 if printf '%s\n' "$1" |
grep -q ^
-; then
36 echo "$progname: $1: Unknown option" >&2
44 opt_verbose
=$
(($opt_verbose - $opt_quiet))
46 if test "$opt_help" = "1"; then
47 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
50 Create subbranches using '.' as level delimiter.
52 Usage: $progname OPTION
58 Delete current branch after merging it to parent. Used when there's
59 no need to document the existence of the branch, and a fast-forward
60 merge will do just fine.
64 Merge the current branch to the parent branch using --no-ff in
65 git(1). This creates a merge commit even if a fast-forward is
66 possible. Useful to group related changes together.
68 Change the active branch (git checkout) to the parent branch, i.e.,
69 the part of the branch name before the final full stop. If no parent
70 branch exists, you will be prompted to create one on 'master'.
72 Be more quiet. Can be repeated to increase silence.
74 Squash the branch into the parent branch, all commits will be
77 Increase level of verbosity. Can be repeated.
79 Print version information.
81 When the -D, -m, -p or -s option is used and there are no parent
82 branches (there are no full stops ('.') in the current branch name), the
83 branch will be merged or squashed to 'master'.
85 If no options are specified, a new "subbranch" will be created from the
86 current branch by postfixing it with ".BRANCHNAME" where BRANCHNAME is
87 specified on the command line. An exception is made when the current
88 branch is 'master', in that case the old branch name is not used as
91 The GITWIP_GIT environment variable can be set to a specific git(1)
92 executable to use. Example:
94 export GITWIP_GIT=/usr/bin/git
101 test -n "$GITWIP_GIT" && CMD_GIT
="$GITWIP_GIT" || CMD_GIT
=git
102 curr
="$($CMD_GIT rev-parse --abbrev-ref HEAD)"
104 test "$curr" = "master" -o "$curr" = "HEAD" && use_new_branch
=1
107 test -n "$1" && { ext
="$1"; shift; }
110 # Loop until the user says 'y'.
112 until test "$resp" = "y"; do
113 echo -n $progname: Type
\'y
\' + Enter to $
*...
>&2
118 chkopt
="$opt_delete$opt_merge$opt_parent$opt_squash"
119 if test -n "$(echo $chkopt | grep 1)"; then
120 if test -n "$(echo "$curr" | grep '\.')"; then
121 # Current branch contains a full stop, so it has a parent
122 parent
="$(echo "$curr" | rev | cut -d . -f 2- | rev)"
124 # Current branch has no parents, prepare for merge or squash to
126 test "$opt_squash" = "1" && ms_str
=squash || ms_str
=merge
127 if test "$curr" = "master"; then
128 echo Is already on master
, \
129 nowhere to
$ms_str branch
>&2
132 if test "$opt_parent" = "1"; then
133 loop_until_y
set active branch to
\'master
\' \
134 \
($CMD_GIT checkout\
)
136 loop_until_y
$ms_str $curr to master
141 $CMD_GIT branch | cut
-c 3- |
grep "^$parent\$" ||
{
142 echo $progname: $parent: Parent branch does not exist
>&2
143 loop_until_y create the
\'$parent\' branch on
\'master
\'
144 $CMD_GIT branch
"$parent" master
146 $CMD_GIT checkout
$parent &&
147 if test "$opt_delete" = "1"; then
148 # Delete current branch after merge to parent, use fast-forward
151 $CMD_GIT branch
-d $curr
152 elif test "$opt_squash" = "1"; then
153 # Squash the current branch to parent, combine all commits into
155 $CMD_GIT merge
--squash $curr
156 elif test "$opt_merge" = "1"; then
157 # Merge current branch into parent, always create merge commit
158 # even if a fast-forward merge is possible.
159 $CMD_GIT merge
--no-ff $curr
160 $CMD_GIT branch
-d $curr
165 if test "$use_new_branch" = "1"; then
166 # Create new branch without prefix
167 $CMD_GIT branch
"$ext" ||
exit 1
168 $CMD_GIT checkout
"$ext"
170 # Create new branch, use current branch name as prefix
171 $CMD_GIT branch
"$curr.$ext" ||
exit 1
172 $CMD_GIT checkout
"$curr.$ext"
175 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :