Skip to content

Commit

Permalink
exclude branches from octopus with -e pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ozangunalp committed Aug 22, 2016
1 parent f419866 commit aeced44
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
14 changes: 13 additions & 1 deletion doc/git-octopus.1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ git-octopus \- extends git\-merge with branch naming patterns\&.
.SH "SYNOPSIS"
.sp
.nf
\fIgit octopus\fR [\-n|\-c] [\-s <n>] [<pattern>\&...]
\fIgit octopus\fR [\-n|\-c] [\-s <n>] [\-e <pattern>] [<pattern>\&...]
\fIgit octopus\fR \-v
.fi
.SH "DESCRIPTION"
Expand Down Expand Up @@ -63,6 +63,11 @@ set to false\&. Use this option to override the latter\&.
Chunk mode: the merge is performed by subsets of <n> branches\&. This is meant to help reading the log graph when lots of branches are merged\&.
.RE
.PP
\-e <pattern>
.RS 4
Exclude pattern: the merge excludes branches matching the <pattern>\&.
.RE
.PP
\-v
.RS 4
Prints the version of
Expand Down Expand Up @@ -106,6 +111,13 @@ Defines a branch naming pattern that
would use by default\&. Use multiple lines to define several patterns\&. See
git\-config(1)\&.
.RE
.PP
octopus\&.excludePattern
.RS 4
Defines a branch naming pattern that
\fIgit octopus\fR
will exclude by default\&.
.RE
.SH "SEE ALSO"
.sp
git\-merge(1), git\-ls\-remote(1), git\-conflict(1)\&.
Expand Down
31 changes: 28 additions & 3 deletions src/git-octopus
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ usage: git octopus [options] [<pattern>...]
-n leaves the repository back to HEAD
-c Commit the resulting merge in the current branch.
-s <n> do the octopus by chunk of n branches.
-e <p> exclude branches matching the pattern.
-v prints the version of git-octopus
EOF
exit
}

line_break(){
removeAllFrom() {
from=$1
remove=$2
for i in $remove; do
from=${from/$i/}
done
echo "$from"
}

line_break() {
echo "-----------------------------------------------------------"
}

Expand All @@ -21,7 +31,7 @@ triggeredBranch=$(git symbolic-ref --short HEAD 2> /dev/null) ||
triggeredSha1=$(git rev-parse --verify HEAD)


signalHandler(){
signalHandler() {
echo
line_break
echo "Stoping..."
Expand All @@ -34,7 +44,7 @@ signalHandler(){

doCommit=$(git config octopus.commit)
splitByChunk=false
while getopts "nhvcs:" opt; do
while getopts "nhvcs:e:" opt; do
case "$opt" in
h)
usage
Expand All @@ -54,6 +64,9 @@ while getopts "nhvcs:" opt; do
splitByChunk=true
chunkSize=$OPTARG
;;
e)
exclude+=" $OPTARG"
;;
\?)
exit 1
;;
Expand All @@ -69,18 +82,30 @@ shift $(expr $OPTIND - 1)

#Retrive patterns written in the conf
patterns=$(git config --get-all octopus.pattern)
excludePatterns=$(git config --get-all octopus.excludePattern)

#Overriding the conf with the patterns given as parameters
if [[ -n "$@" ]] ; then
patterns=$@
fi
if [[ -n "$exclude" ]]; then
excludePatterns=${exclude:1}
fi

#Exit code 0 if nothing to merge
if [[ -z "$patterns" ]] ; then
exit 0
fi

branches=$(git ls-remote . $patterns | cut -d $'\t' -f 2)
#Get nothing if excludePatterns is empty
[[ -n "$excludePatterns" ]] && excludedBranches=$(git ls-remote . $excludePatterns | cut -d $'\t' -f 2)
branches=$(removeAllFrom "$branches" "$excludedBranches")

[[ -z "$excludedBranches" ]] || echo "Excluding branches :"
for branch in $excludedBranches ; do
echo $'\t'$branch
done

if [ -z "$branches" ]; then
echo "No branch matching $patterns were found"
Expand Down
6 changes: 6 additions & 0 deletions test/exclude_pattern_config_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM lesfurets/octopus-tests:simple_merge_latest
ADD test.sh /home/
ADD bin /usr/local/bin
RUN chmod +x /home/test.sh
WORKDIR /home/octopus-tests/
CMD /home/test.sh
25 changes: 25 additions & 0 deletions test/exclude_pattern_config_test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

#FIXME
git status &> /dev/null

git checkout features/feat1
git config octopus.pattern features/*
git config --add octopus.pattern master

git config octopus.excludePattern "features/feat3"

git octopus
merged=`git branch --merged`
if [[ $merged != *feat1* ]] ; then
exit 1
fi
if [[ $merged != *feat2* ]] ; then
exit 1
fi
if [[ $merged == *feat3* ]] ; then
exit 1
fi
if [[ $merged != *master* ]] ; then
exit 1
fi

0 comments on commit aeced44

Please sign in to comment.