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

Feature/branch prefixes as subcommands #6463

Open
wants to merge 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ debian/files
debian/*.substvars
debian/*.debhelper.log
debian/*/*

# use this directory to init a git repo and test the implementation
test/
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Authors are (ordered by first commit date):
- Eric Holmes
- Vedang Manerikar
- Myke Hines
- Tobias Szczepanski

Portions derived from other open source works are clearly marked.
5 changes: 5 additions & 0 deletions Changes.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Release date: **not yet**
* `git flow init` now detects situations where origin already has gitflow
branches set up, and behaves accordingly (thanks Emre Berge Ergenekon).

* `git flow init` now asks for a dedicated delimiter, which provides
consistency in all branch names. Branch names are constructed as follows:
`<prefix><delimiter><name>`.
E.g. a custom delimiter `_` leads to `feature_some-feature`

* `git flow feature finish` can now be called without a feature branch
name(prefix) argument and will finish the current branch, if on any.

Expand Down
39 changes: 32 additions & 7 deletions git-flow
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,24 @@ fi
export GITFLOW_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

usage() {
local featurePrefix=$(git config --get gitflow.prefix.feature)
featurePrefix=${featurePrefix:-feature}
local releasePrefix=$(git config --get gitflow.prefix.release)
releasePrefix=${releasePrefix:-release}
local hotfixPrefix=$(git config --get gitflow.prefix.hotfix)
hotfixPrefix=${hotfixPrefix:-hotfix}
local supportPrefix=$(git config --get gitflow.prefix.support)
supportPrefix=${supportPrefix:-support}

echo "usage: git flow <subcommand>"
echo
echo "Available subcommands are:"
echo " init Initialize a new git repo with support for the branching model."
echo " feature Manage your feature branches."
echo " release Manage your release branches."
echo " hotfix Manage your hotfix branches."
echo " support Manage your support branches."
echo " version Shows version information."
printf ' %s\t%s\n' "init" "Initialize a new git repo with support for the branching model."
printf ' %s\t%s\n' "$featurePrefix" "Manage your $featurePrefix branches."
printf ' %s\t%s\n' "$releasePrefix" "Manage your $releasePrefix branches."
printf ' %s\t%s\n' "$hotfixPrefix" "Manage your $hotfixPrefix branches."
printf ' %s\t%s\n' "$supportPrefix" "Manage your $supportPrefix branches."
printf ' %s\t%s\n' "version" "Shows version information."
echo
echo "Try 'git flow <subcommand> help' for details."
}
Expand Down Expand Up @@ -91,6 +100,22 @@ main() {
# sanity checks
SUBCOMMAND="$1"; shift

# use configured prefix as sub-command
case $SUBCOMMAND in
init) ;;
version) ;;
*)
if [ "$(git config --get gitflow.prefix.feature)" = "$SUBCOMMAND" ]; then
SUBCOMMAND="feature";
elif [ "$(git config --get gitflow.prefix.release)" = "$SUBCOMMAND" ]; then
SUBCOMMAND="release";
elif [ "$(git config --get gitflow.prefix.hotfix)" = "$SUBCOMMAND" ]; then
SUBCOMMAND="hotfix";
elif [ "$(git config --get gitflow.prefix.support)" = "$SUBCOMMAND" ]; then
SUBCOMMAND="support";
fi
esac

if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
usage
exit 1
Expand All @@ -114,7 +139,7 @@ main() {
fi

# run the specified action
if [ $SUBACTION != "help" ] && [ $SUBCOMMAND != "init" ] ; then
if [ $SUBACTION != "help" ] && [ $SUBCOMMAND != "init" ] && [ $SUBCOMMAND != "version" ] ; then
init
fi
cmd_$SUBACTION "$@"
Expand Down
47 changes: 25 additions & 22 deletions git-flow-feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
Expand Down Expand Up @@ -40,19 +41,21 @@ init() {
require_git_repo
require_gitflow_initialized
gitflow_load_settings
PREFIX=$(git config --get gitflow.prefix.feature)
}

DELIMITER="$(git config --get gitflow.prefix.delimiter)";
PREFIX="$(git config --get gitflow.prefix.feature)";

usage() {
echo "usage: git flow feature [list] [-v]"
echo " git flow feature start [-F] <name> [<base>]"
echo " git flow feature finish [-rFkDS] [<name|nameprefix>]"
echo " git flow feature publish <name>"
echo " git flow feature track <name>"
echo " git flow feature diff [<name|nameprefix>]"
echo " git flow feature rebase [-i] [<name|nameprefix>]"
echo " git flow feature checkout [<name|nameprefix>]"
echo " git flow feature pull [-r] <remote> [<name>]"
echo "usage: git flow $PREFIX [list] [-v]"
echo " git flow $PREFIX start [-F] <name> [<base>]"
echo " git flow $PREFIX finish [-rFkDS] [<name|nameprefix>]"
echo " git flow $PREFIX publish <name>"
echo " git flow $PREFIX track <name>"
echo " git flow $PREFIX diff [<name|nameprefix>]"
echo " git flow $PREFIX rebase [-i] [<name|nameprefix>]"
echo " git flow $PREFIX checkout [<name|nameprefix>]"
echo " git flow $PREFIX pull [-r] <remote> [<name>]"
}

cmd_default() {
Expand All @@ -66,7 +69,7 @@ cmd_list() {
local feature_branches
local current_branch
local short_names
feature_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
feature_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX$DELIMITER")
if [ -z "$feature_branches" ]; then
warn "No feature branches exist."
warn ""
Expand All @@ -77,7 +80,7 @@ cmd_list() {
exit 0
fi
current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g")
short_names=$(echo "$feature_branches" | sed "s ^$PREFIX$DELIMITER g")

# determine column width first
local width=0
Expand All @@ -90,7 +93,7 @@ cmd_list() {

local branch
for branch in $short_names; do
local fullname=$PREFIX$branch
local fullname="$PREFIX$DELIMITER$branch"
local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
Expand Down Expand Up @@ -135,21 +138,21 @@ expand_nameprefix_arg() {

local expanded_name
local exitcode
expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX")
expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX$DELIMITER")
exitcode=$?
case $exitcode in
0) NAME=$expanded_name
BRANCH=$PREFIX$NAME
BRANCH="$PREFIX$DELIMITER$NAME"
;;
*) exit 1 ;;
esac
}

use_current_feature_branch_name() {
local current_branch=$(git_current_branch)
if startswith "$current_branch" "$PREFIX"; then
if startswith "$current_branch" "$PREFIX$DELIMITER"; then
BRANCH=$current_branch
NAME=${BRANCH#$PREFIX}
NAME=${BRANCH#$PREFIX$DELIMITER}
else
warn "The current HEAD is no feature branch."
warn "Please specify a <name> argument."
Expand All @@ -160,7 +163,7 @@ use_current_feature_branch_name() {
expand_nameprefix_arg_or_current() {
if [ "$NAME" != "" ]; then
expand_nameprefix_arg
require_branch "$PREFIX$NAME"
require_branch "$PREFIX$DELIMITER$NAME"
else
use_current_feature_branch_name
fi
Expand All @@ -179,7 +182,7 @@ parse_args() {

# read arguments into global variables
NAME=$1
BRANCH=$PREFIX$NAME
BRANCH=$PREFIX$DELIMITER$NAME
}

parse_remote_name() {
Expand All @@ -190,7 +193,7 @@ parse_remote_name() {
# read arguments into global variables
REMOTE=$1
NAME=$2
BRANCH=$PREFIX$NAME
BRANCH=$PREFIX$DELIMITER$NAME
}

cmd_start() {
Expand Down Expand Up @@ -431,7 +434,7 @@ cmd_diff() {
BASE=$(git merge-base "$DEVELOP_BRANCH" "$BRANCH")
git diff "$BASE..$BRANCH"
else
if ! git_current_branch | grep -q "^$PREFIX"; then
if ! git_current_branch | grep -q "^$PREFIX$DELIMITER"; then
die "Not on a feature branch. Name one explicitly."
fi

Expand Down Expand Up @@ -496,7 +499,7 @@ cmd_pull() {
# die if the current feature branch differs from the requested $NAME
# argument.
local current_branch=$(git_current_branch)
if startswith "$current_branch" "$PREFIX"; then
if startswith "$current_branch" "$PREFIX$DELIMITER"; then
# we are on a local feature branch already, so $BRANCH must be equal to
# the current branch
avoid_accidental_cross_branch_action || die
Expand Down
29 changes: 16 additions & 13 deletions git-flow-hotfix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
Expand Down Expand Up @@ -40,16 +41,18 @@ init() {
require_git_repo
require_gitflow_initialized
gitflow_load_settings
VERSION_PREFIX=$(eval "echo `git config --get gitflow.prefix.versiontag`")
PREFIX=$(git config --get gitflow.prefix.hotfix)
}

VERSION_PREFIX=$(eval "echo $(git config --get gitflow.prefix.versiontag)")
DELIMITER="$(git config --get gitflow.prefix.delimiter)";
PREFIX=$(git config --get gitflow.prefix.hotfix)

usage() {
echo "usage: git flow hotfix [list] [-v]"
echo " git flow hotfix start [-F] <version> [<base>]"
echo " git flow hotfix finish [-Fsumpk] <version>"
echo " git flow hotfix publish <version>"
echo " git flow hotfix track <version>"
echo "usage: git flow $PREFIX [list] [-v]"
echo " git flow $PREFIX start [-F] <version> [<base>]"
echo " git flow $PREFIX finish [-Fsumpk] <version>"
echo " git flow $PREFIX publish <version>"
echo " git flow $PREFIX track <version>"
}

cmd_default() {
Expand All @@ -63,7 +66,7 @@ cmd_list() {
local hotfix_branches
local current_branch
local short_names
hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX$DELIMITER")
if [ -z "$hotfix_branches" ]; then
warn "No hotfix branches exist."
warn ""
Expand All @@ -74,7 +77,7 @@ cmd_list() {
exit 0
fi
current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$hotfix_branches" | sed "s ^$PREFIX g")
short_names=$(echo "$hotfix_branches" | sed "s ^$PREFIX$DELIMITER g")

# determine column width first
local width=0
Expand All @@ -87,7 +90,7 @@ cmd_list() {

local branch
for branch in $short_names; do
local fullname=$PREFIX$branch
local fullname=$PREFIX$DELIMITER$branch
local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
local master_sha=$(git rev-parse "$MASTER_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
Expand Down Expand Up @@ -129,7 +132,7 @@ parse_args() {

# read arguments into global variables
VERSION=$1
BRANCH=$PREFIX$VERSION
BRANCH=$PREFIX$DELIMITER$VERSION
}

require_version_arg() {
Expand All @@ -149,9 +152,9 @@ require_base_is_on_master() {
}

require_no_existing_hotfix_branches() {
local hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
local hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX$DELIMITER")
local first_branch=$(echo ${hotfix_branches} | head -n1)
first_branch=${first_branch#$PREFIX}
first_branch=${first_branch#$PREFIX$DELIMITER}
[ -z "$hotfix_branches" ] || \
die "There is an existing hotfix branch ($first_branch). Finish that one first."
}
Expand Down