Skip to content

Commit

Permalink
Merge pull request #19 from ozangunalp/exclude-pattern
Browse files Browse the repository at this point in the history
Exclude pattern
  • Loading branch information
apflieger authored Sep 7, 2016
2 parents ffc0e49 + f572907 commit 78d7a16
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/doc/git-octopus.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git-octopus - extends git-merge with branch naming patterns.
SYNOPSIS
--------
[verse]
'git octopus' [-n|-c] [-s <n>] [<pattern>...]
'git octopus' [-n|-c] [-s <n>] [-e <pattern>] [<pattern>...]
'git octopus' -v

DESCRIPTION
Expand All @@ -39,6 +39,10 @@ Commit the resulting merge in the current branch. This is the default behavior u
+
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.

-e <pattern>::
+
Exclude pattern: the merge excludes branches matching the <pattern>.

-v::
+
Prints the version of `git-octopus`
Expand All @@ -63,6 +67,9 @@ octopus.pattern::
+
Defines a branch naming pattern that 'git octopus' would use by default. Use multiple lines to define several patterns. See link:git-config.html[git-config(1)].

octopus.excludePattern::
+
Defines a branch naming pattern that 'git octopus' will exclude by default.

SEE ALSO
--------
Expand Down
33 changes: 29 additions & 4 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 Expand Up @@ -121,7 +146,7 @@ do
sha1sChunk=" ${sha1s[@]:$i:$chunkSize}"

alreadyUpToDate=true
for sha1 in "${sha1sChunk[@]}"
for sha1 in ${sha1sChunk[@]}
do
git merge-base --is-ancestor $sha1 HEAD || alreadyUpToDate=false
done
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 78d7a16

Please sign in to comment.