Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitflow
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
gitflow
Commits
886c9e15
Commit
886c9e15
authored
Feb 06, 2010
by
Vincent Driessen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/tidy-up' into develop
parents
5474e46a
27592dd7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
255 additions
and
198 deletions
+255
-198
Makefile
Makefile
+2
-1
git-flow
git-flow
+5
-120
git-flow-feature
git-flow-feature
+35
-29
git-flow-hotfix
git-flow-hotfix
+22
-16
git-flow-release
git-flow-release
+22
-16
git-flow-support
git-flow-support
+22
-16
gitflow-common
gitflow-common
+147
-0
gitflow-shFlags
gitflow-shFlags
+0
-0
No files found.
Makefile
View file @
886c9e15
...
@@ -10,7 +10,8 @@ SCRIPT_FILES+=git-flow-hotfix
...
@@ -10,7 +10,8 @@ SCRIPT_FILES+=git-flow-hotfix
SCRIPT_FILES
+=
git-flow-release
SCRIPT_FILES
+=
git-flow-release
SCRIPT_FILES
+=
git-flow-support
SCRIPT_FILES
+=
git-flow-support
SCRIPT_FILES
+=
git-flow-version
SCRIPT_FILES
+=
git-flow-version
SCRIPT_FILES
+=
shFlags.sh
SCRIPT_FILES
+=
gitflow-common
SCRIPT_FILES
+=
gitflow-shFlags
all
:
all
:
@
echo
"usage: make install"
@
echo
"usage: make install"
...
...
git-flow
View file @
886c9e15
...
@@ -18,21 +18,13 @@ if [ "$DEBUG" = "yes" ]; then
...
@@ -18,21 +18,13 @@ if [ "$DEBUG" = "yes" ]; then
set
-x
set
-x
fi
fi
export
GIT_DIR
=
$(
git rev-parse
--git-dir
)
export
GITFLOW_DIR
=
$(
dirname
"
$0
"
)
export
GITFLOW_DIR
=
$(
dirname
"
$0
"
)
export
GIT_DIR
=
$(
git rev-parse
--git-dir
)
export
MASTER_BRANCH
=
$(
git config
--get
gitflow.branch.master
||
echo
master
)
export
MASTER_BRANCH
=
$(
git config
--get
gitflow.branch.master
||
echo
master
)
export
DEVELOP_BRANCH
=
$(
git config
--get
gitflow.branch.develop
||
echo
develop
)
export
DEVELOP_BRANCH
=
$(
git config
--get
gitflow.branch.develop
||
echo
develop
)
export
ORIGIN
=
$(
git config
--get
gitflow.origin
||
echo
origin
)
export
ORIGIN
=
$(
git config
--get
gitflow.origin
||
echo
origin
)
export
README
=
$(
git config
--get
gitflow.readme
||
echo
README
)
export
README
=
$(
git config
--get
gitflow.readme
||
echo
README
)
warn
()
{
echo
"
$@
"
>
&2
;
}
die
()
{
warn
"
$@
"
;
exit
1
;
}
has
()
{
local
item
=
$1
;
shift
echo
"
$@
"
|
grep
-q
"
$item
"
}
usage
()
{
usage
()
{
echo
"usage: git flow <subcommand>"
echo
"usage: git flow <subcommand>"
echo
echo
...
@@ -53,11 +45,12 @@ main() {
...
@@ -53,11 +45,12 @@ main() {
exit
1
exit
1
fi
fi
# load common functionality
.
"
$GITFLOW_DIR
/gitflow-common"
# use the shFlags project to parse the command line arguments
# use the shFlags project to parse the command line arguments
.
"
$GITFLOW_DIR
/
shFlags.sh
"
.
"
$GITFLOW_DIR
/
gitflow-shFlags
"
FLAGS_PARENT
=
"git flow"
FLAGS_PARENT
=
"git flow"
#DEFINE_boolean quiet 0 'run without output' q
#DEFINE_boolean verbose 0 'run verbose (more output)' v
FLAGS
"
$@
"
||
exit
$?
FLAGS
"
$@
"
||
exit
$?
eval set
--
"
${
FLAGS_ARGV
}
"
eval set
--
"
${
FLAGS_ARGV
}
"
...
@@ -73,11 +66,6 @@ main() {
...
@@ -73,11 +66,6 @@ main() {
die
"Not a git repository"
die
"Not a git repository"
fi
fi
# get all available branches
LOCAL_BRANCHES
=
$(
git branch |
sed
's/^[* ] //'
)
REMOTE_BRANCHES
=
$(
git branch
-r
|
sed
's/^[* ] //'
)
ALL_BRANCHES
=
"
$LOCAL_BRANCHES
$REMOTE_BRANCHES
"
# run command
# run command
.
"
$GITFLOW_DIR
/git-flow-
$SUBCOMMAND
"
.
"
$GITFLOW_DIR
/git-flow-
$SUBCOMMAND
"
FLAGS_PARENT
=
"git flow
$SUBCOMMAND
"
FLAGS_PARENT
=
"git flow
$SUBCOMMAND
"
...
@@ -99,109 +87,6 @@ main() {
...
@@ -99,109 +87,6 @@ main() {
cmd_
$SUBACTION
"
$@
"
cmd_
$SUBACTION
"
$@
"
}
}
gitflow_test_clean_working_tree
()
{
if
!
git diff
--no-ext-diff
--ignore-submodules
--quiet
--exit-code
;
then
return
1
elif
!
git diff-index
--cached
--quiet
--ignore-submodules
HEAD
--
;
then
return
2
else
return
0
fi
}
gitflow_require_clean_working_tree
()
{
gitflow_test_clean_working_tree
result
=
$?
if
[
$result
-eq
1
]
;
then
die
"fatal: Working tree contains unstaged changes. Aborting."
fi
if
[
$result
-eq
2
]
;
then
die
"fatal: Index contains uncommited changes. Aborting."
fi
}
gitflow_require_local_branch
()
{
if
!
has
$1
$LOCAL_BRANCHES
;
then
die
"fatal: Local branch '
$1
' does not exist and is required."
fi
}
gitflow_require_remote_branch
()
{
if
!
has
$1
$REMOTE_BRANCHES
;
then
die
"Remote branch '
$1
' does not exist and is required."
fi
}
gitflow_require_branch
()
{
if
!
has
$1
$ALL_BRANCHES
;
then
die
"Branch '
$1
' does not exist and is required."
fi
}
gitflow_require_branch_absent
()
{
if
has
$1
$ALL_BRANCHES
;
then
die
"Branch '
$1
' already exists. Pick another name."
fi
}
#
# gitflow_test_branches_equal()
#
# Tests whether branches and their "origin" counterparts have diverged and need
# merging first. It returns error codes to provide more detail, like so:
#
# 0 Branch heads point to the same commit
# 1 First given branch needs fast-forwarding
# 2 Second given branch needs fast-forwarding
# 3 Branch needs a real merge
#
gitflow_test_branches_equal
()
{
commit1
=
$(
git rev-parse
"
$1
"
)
commit2
=
$(
git rev-parse
"
$2
"
)
if
[
"
$commit1
"
!=
"
$commit2
"
]
;
then
base
=
$(
git merge-base
"
$commit1
"
"
$commit2
"
)
if
[
"
$commit1
"
=
"
$base
"
]
;
then
return
1
elif
[
"
$commit2
"
=
"
$base
"
]
;
then
return
2
else
return
3
fi
else
return
0
fi
}
gitflow_require_branches_equal
()
{
gitflow_require_local_branch
"
$1
"
gitflow_require_remote_branch
"
$2
"
gitflow_test_branches_equal
"
$1
"
"
$2
"
status
=
$?
if
[
$status
-gt
0
]
;
then
warn
"Branches '
$1
' and '
$2
' have diverged."
if
[
$status
-eq
1
]
;
then
die
"And branch '
$1
' may be fast-forwarded."
elif
[
$status
-eq
2
]
;
then
# Warn here, since there is no harm in being ahead
warn
"And local branch '
$1
' is ahead of '
$2
'."
else
die
"Branches need merging first."
fi
fi
}
#
# gitflow_is_branch_merged_into()
#
# Checks whether branch $1 is succesfully merged into $2
#
gitflow_is_branch_merged_into
()
{
local
SUBJECT
=
$1
local
BASE
=
$2
ALL_MERGES
=
$(
git branch
--contains
$SUBJECT
|
sed
's/^[* ] //'
)
has
$BASE
$ALL_MERGES
}
# helper functions for common reuse
# helper functions for common reuse
max
()
{
if
[
"
$1
"
-gt
"
$2
"
]
;
then
echo
"
$1
"
;
else
echo
"
$2
"
;
fi
;
}
max
()
{
if
[
"
$1
"
-gt
"
$2
"
]
;
then
echo
"
$1
"
;
else
echo
"
$2
"
;
fi
;
}
...
...
git-flow-feature
View file @
886c9e15
...
@@ -32,28 +32,33 @@ cmd_list() {
...
@@ -32,28 +32,33 @@ cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
parse_args "$@"
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
typeset feature_branches
if [ -z "$FEATURE_BRANCHES" ]; then
typeset current_branch
typeset short_names
feature_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$feature_branches" ]; then
warn "No feature branches exist."
warn "No feature branches exist."
exit 0
exit 0
fi
fi
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g")
CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
SHORT_NAMES=$(echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
# determine column width first
width=0
typeset -i width=0
for branch in $SHORT_NAMES; do
typeset branch
len=$(($(echo "$branch" | wc -c) - 1))
for branch in $short_names; do
typeset -i len=${#branch}
width=$(max $width $len)
width=$(max $width $len)
done
done
width=$(($width + 3))
width=width+3
for branch in $SHORT_NAMES; do
typeset branch
fullname="$PREFIX$branch"
for branch in $short_names; do
base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
typeset fullname="$PREFIX$branch"
develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
branch_sha=$(git rev-parse "$fullname")
typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
if [ "$fullname" = "$CURRENT_BRANCH" ]; then
typeset branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
printf "* "
else
else
printf " "
printf " "
...
@@ -82,26 +87,27 @@ cmd_help() {
...
@@ -82,26 +87,27 @@ cmd_help() {
}
}
resolve_name_by_prefix() {
resolve_name_by_prefix() {
typeset matches
typeset -i num_matches
# first, check if there is a perfect match
# first, check if there is a perfect match
if has "$LOCAL_BRANCHES" "$PREFIX$1"; then
if has "$LOCAL_BRANCHES" "$PREFIX$1"; then
echo "$1"
echo "$1"
return 0
return 0
fi
fi
MATCHES
="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
matches
="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
NUM_MATCHES=$(echo "$MATCHES
" | wc -l)
num_matches=$(echo "$matches
" | wc -l)
if [ -z "$
MATCHES
" ]; then
if [ -z "$
matches
" ]; then
# no prefix match, so take it literally
# no prefix match, so take it literally
echo "$1"
echo "$1"
else
else
if [ $NUM_MATCHES -eq 1 ]; then
if [ $num_matches -eq 1 ]; then
# sed arg looks a bit weird, but $PREFIX should not contain spaces,
echo "${matches#$PREFIX}"
# so this one is safe
echo "$MATCHES" | sed "s $PREFIX g"
else
else
# multiple matches, cannot decide
# multiple matches, cannot decide
warn "Multiple branches match for prefix '$1':"
warn "Multiple branches match for prefix '$1':"
for match in $
MATCHES
; do
for match in $
matches
; do
warn "- $match"
warn "- $match"
done
done
die "Aborting. Use an unambiguous prefix."
die "Aborting. Use an unambiguous prefix."
...
@@ -127,11 +133,11 @@ expand_name_arg_prefix() {
...
@@ -127,11 +133,11 @@ expand_name_arg_prefix() {
}
}
expand_name_arg_prefix_or_current() {
expand_name_arg_prefix_or_current() {
CURRENT_BRANCH
=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
current_branch
=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
if [ "$NAME" != "" ]; then
if [ "$NAME" != "" ]; then
expand_name_arg_prefix
expand_name_arg_prefix
elif [ "$
CURRENT_BRANCH
" != "" ]; then
elif [ "$
current_branch
" != "" ]; then
BRANCH="$
CURRENT_BRANCH
"
BRANCH="$
current_branch
"
NAME=$(echo "$BRANCH" | sed "s?$PREFIX??g")
NAME=$(echo "$BRANCH" | sed "s?$PREFIX??g")
else
else
warn "The current HEAD is no feature branch."
warn "The current HEAD is no feature branch."
...
@@ -364,8 +370,8 @@ cmd_diff() {
...
@@ -364,8 +370,8 @@ cmd_diff() {
BASE=$(git merge-base $DEVELOP_BRANCH $BRANCH)
BASE=$(git merge-base $DEVELOP_BRANCH $BRANCH)
git diff $BASE..$BRANCH
git diff $BASE..$BRANCH
else
else
CURRENT_BRANCH
=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
current_branch
=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
if ! echo "$
CURRENT_BRANCH
" | grep -q "^$PREFIX"; then
if ! echo "$
current_branch
" | grep -q "^$PREFIX"; then
die "Not on a feature branch. Name one explicitly."
die "Not on a feature branch. Name one explicitly."
fi
fi
...
@@ -383,7 +389,7 @@ cmd_rebase() {
...
@@ -383,7 +389,7 @@ cmd_rebase() {
gitflow_require_branch "$BRANCH"
gitflow_require_branch "$BRANCH"
git checkout -q "$BRANCH"
git checkout -q "$BRANCH"
OPTS=
typeset
OPTS=
if flag interactive; then
if flag interactive; then
OPTS="$OPTS -i"
OPTS="$OPTS -i"
fi
fi
...
...
git-flow-hotfix
View file @
886c9e15
...
@@ -30,28 +30,33 @@ cmd_list() {
...
@@ -30,28 +30,33 @@ cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
parse_args "$@"
HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
typeset hotfix_branches
if [ -z "$HOTFIX_BRANCHES" ]; then
typeset current_branch
typeset short_names
hotfix_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$hotfix_branches" ]; then
warn "No hotfix branches exist."
warn "No hotfix branches exist."
exit 0
exit 0
fi
fi
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$hotfix_branches" | sed "s?^$PREFIX??g")
CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
SHORT_NAMES=$(echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
# determine column width first
width=0
typeset -i width=0
for branch in $SHORT_NAMES; do
typeset branch
len=$(($(echo "$branch" | wc -c) - 1))
for branch in $short_names; do
typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
width=$(max $width $len)
done
done
width=$(($width + 3))
width=width+3
for branch in $SHORT_NAMES; do
typeset branch
fullname="$PREFIX$branch"
for branch in $short_names; do
base=$(git merge-base "$fullname" "$MASTER_BRANCH")
typeset fullname="$PREFIX$branch"
master_sha=$(git rev-parse "$MASTER_BRANCH")
typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
branch_sha=$(git rev-parse "$fullname")
typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
if [ "$fullname" = "$CURRENT_BRANCH" ]; then
typeset branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
printf "* "
else
else
printf " "
printf " "
...
@@ -61,7 +66,8 @@ cmd_list() {
...
@@ -61,7 +66,8 @@ cmd_list() {
if [ "$branch_sha" = "$master_sha" ]; then
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
printf "(no commits yet)"
else
else
tagname=$(git name-rev --tags --no-undefined --name-only $base)
typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
typeset nicename
if [ "$tagname" != "" ]; then
if [ "$tagname" != "" ]; then
nicename="$tagname"
nicename="$tagname"
else
else
...
...
git-flow-release
View file @
886c9e15
...
@@ -41,28 +41,34 @@ cmd_list() {
...
@@ -41,28 +41,34 @@ cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
parse_args "$@"
RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
typeset release_branches
if [ -z "$RELEASE_BRANCHES" ]; then
typeset current_branch
typeset short_names
release_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$release_branches" ]; then
warn "No release branches exist."
warn "No release branches exist."
exit 0
exit 0
fi
fi
CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
SHORT_NAMES=$(echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g")
short_names=$(echo "$release_branches" | sed "s?^$PREFIX??g")
# determine column width first
# determine column width first
width=0
typeset -i width=0
for branch in $SHORT_NAMES; do
typeset branch
len=$(($(echo "$branch" | wc -c) - 1))
for branch in $short_names; do
typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
width=$(max $width $len)
done
done
width=$(($width + 3))
width=width+3
for branch in $SHORT_NAMES; do
typeset branch
fullname="$PREFIX$branch"
for branch in $short_names; do
base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
typeset fullname="$PREFIX$branch"
develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
branch_sha=$(git rev-parse "$fullname")
typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
if [ "$fullname" = "$CURRENT_BRANCH" ]; then
typeset branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
printf "* "
else
else
printf " "
printf " "
...
@@ -72,7 +78,7 @@ cmd_list() {
...
@@ -72,7 +78,7 @@ cmd_list() {
if [ "$branch_sha" = "$develop_sha" ]; then
if [ "$branch_sha" = "$develop_sha" ]; then
printf "(no commits yet)"
printf "(no commits yet)"
else
else
nicename="$(git rev-parse --short $base)"
typeset
nicename="$(git rev-parse --short $base)"
printf "(based on $nicename)"
printf "(based on $nicename)"
fi
fi
else
else
...
...
git-flow-support
View file @
886c9e15
...
@@ -32,28 +32,33 @@ cmd_list() {
...
@@ -32,28 +32,33 @@ cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
parse_args "$@"
SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
typeset support_branches
if [ -z "$SUPPORT_BRANCHES" ]; then
typeset current_branch
typeset short_names
support_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$support_branches" ]; then
warn "No support branches exist."
warn "No support branches exist."
exit 0
exit 0
fi
fi
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$support_branches" | sed "s?^$PREFIX??g")
CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
SHORT_NAMES=$(echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
# determine column width first
width=0
typeset -i width=0
for branch in $SHORT_NAMES; do
typeset branch
len=$(($(echo "$branch" | wc -c) - 1))
for branch in $short_names; do
typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
width=$(max $width $len)
done
done
width=$(($width + 3))
width=width+3
for branch in $SHORT_NAMES; do
typeset branch
fullname="$PREFIX$branch"
for branch in $short_names; do
base=$(git merge-base "$fullname" "$MASTER_BRANCH")
typeset fullname="$PREFIX$branch"
master_sha=$(git rev-parse "$MASTER_BRANCH")
typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
branch_sha=$(git rev-parse "$fullname")
typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
if [ "$fullname" = "$CURRENT_BRANCH" ]; then
typeset branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
printf "* "
else
else
printf " "
printf " "
...
@@ -63,7 +68,8 @@ cmd_list() {
...
@@ -63,7 +68,8 @@ cmd_list() {
if [ "$branch_sha" = "$master_sha" ]; then
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
printf "(no commits yet)"
else
else
tagname=$(git name-rev --tags --no-undefined --name-only $base)
typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
typeset nicename
if [ "$tagname" != "" ]; then
if [ "$tagname" != "" ]; then
nicename="$tagname"
nicename="$tagname"
else
else
...
...
gitflow-common
0 → 100644
View file @
886c9e15
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
#
# Original blog post presenting this model is found at:
# http://nvie.com/archives/323
#
# Feel free to contribute to this project at:
# http://github.com/nvie/gitflow
#
# Copyright (c) 2010 by Vincent Driessen
# Copyright (c) 2010 by Benedikt Böhm
#
# shell output
warn() { echo "$@" >&2; }
die() { warn "$@"; exit 1; }
# set logic
has() {
typeset item=$1; shift
echo " $@ " | grep -q " $item "
}
# basic math
min() { [ "$1" -le "$2" ] && echo "$1" || echo "$2"; }
max() { [ "$1" -ge "$2" ] && echo "$1" || echo "$2"; }
# basic string matching
startswith() { [ "$1" != "${1#$2}" ]; }
endswith() { [ "$1" != "${1#$2}" ]; }
# convenience functions for checking shFlags flags
flag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -eq $FLAGS_TRUE ]; }
noflag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
#
# Git specific common functionality
#
# get all available branches
LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //')
REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //')
ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
gitflow_test_clean_working_tree() {
if ! git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
return 1
elif ! git diff-index --cached --quiet --ignore-submodules HEAD --; then
return 2
else
return 0
fi
}
gitflow_require_clean_working_tree() {
gitflow_test_clean_working_tree
typeset -i result=$?
if [ $result -eq 1 ]; then
die "fatal: Working tree contains unstaged changes. Aborting."
fi
if [ $result -eq 2 ]; then
die "fatal: Index contains uncommited changes. Aborting."
fi
}
gitflow_require_local_branch() {
if ! has $1 $LOCAL_BRANCHES; then
die "fatal: Local branch '$1' does not exist and is required."
fi
}
gitflow_require_remote_branch() {
if ! has $1 $REMOTE_BRANCHES; then
die "Remote branch '$1' does not exist and is required."
fi
}
gitflow_require_branch() {
if ! has $1 $ALL_BRANCHES; then
die "Branch '$1' does not exist and is required."
fi
}
gitflow_require_branch_absent() {
if has $1 $ALL_BRANCHES; then
die "Branch '$1' already exists. Pick another name."
fi
}
#
# gitflow_test_branches_equal()
#
# Tests whether branches and their "origin" counterparts have diverged and need
# merging first. It returns error codes to provide more detail, like so:
#
# 0 Branch heads point to the same commit
# 1 First given branch needs fast-forwarding
# 2 Second given branch needs fast-forwarding
# 3 Branch needs a real merge
#
gitflow_test_branches_equal() {
typeset commit1=$(git rev-parse "$1")
typeset commit2=$(git rev-parse "$2")
if [ "$commit1" != "$commit2" ]; then
typeset base=$(git merge-base "$commit1" "$commit2")
if [ "$commit1" = "$base" ]; then
return 1
elif [ "$commit2" = "$base" ]; then
return 2
else
return 3
fi
else
return 0
fi
}
gitflow_require_branches_equal() {
gitflow_require_local_branch "$1"
gitflow_require_remote_branch "$2"
gitflow_test_branches_equal "$1" "$2"
typeset -i status=$?
if [ $status -gt 0 ]; then
warn "Branches '$1' and '$2' have diverged."
if [ $status -eq 1 ]; then
die "And branch '$1' may be fast-forwarded."
elif [ $status -eq 2 ]; then
# Warn here, since there is no harm in being ahead
warn "And local branch '$1' is ahead of '$2'."
else
die "Branches need merging first."
fi
fi
}
#
# gitflow_is_branch_merged_into()
#
# Checks whether branch $1 is succesfully merged into $2
#
gitflow_is_branch_merged_into() {
typeset subject=$1
typeset base=$2
typeset all_merges=$(git branch --contains $subject | sed 's/^[* ] //')
has $base $all_merges
}
shFlags.sh
→
gitflow-shFlags
View file @
886c9e15
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment