Skip to content

Commit

Permalink
Merge pull request #1 from Turmio/incoming-linux
Browse files Browse the repository at this point in the history
Incoming linux
  • Loading branch information
Turmio authored Mar 6, 2017
2 parents c6b21b7 + 2c74907 commit 7c03415
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
language: python
language: python

branches:
only:
- gh-pages
- /.*/

install: true

script:
- chmod +x test/hg/bash/test-incoming.sh
- ./test/hg/bash/test-incoming.sh
25 changes: 25 additions & 0 deletions src/hg/bash/incoming.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

ON_NEW=$1
ON_EXISTING=$2
ON_CLOSED=$3

REPO=`echo $(echo "$HG_URL" | sed "s/^file://g")`

#get branch
BRANCH=`hg log --rev $HG_NODE --template "{branch}\n"`
#first commit to branch
FIRST=`hg log -r "min(branch($BRANCH))" --template "{node}\n"`
#is closed
CLOSED=`hg log -r "closed() and branch($BRANCH)" --template "{node}\n" | awk 'NR==1'`

if [ "$HG_NODE" = "$FIRST" ]; then
CMD="$ON_NEW $BRANCH $HG_NODE"
eval $CMD
elif [ "$HG_NODE" = "$CLOSED" ]; then
CMD="$ON_CLOSED $BRANCH $HG_NODE"
eval $CMD
else
CMD="$ON_EXISTING $BRANCH $HG_NODE"
eval $CMD
fi
31 changes: 31 additions & 0 deletions test/hg/bash/add-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Cannot add hook because repository is not defined"
exit 1
fi

if [ -z "$2" ]; then
echo "Cannot add hook because hook is not defined"
exit 1
fi


SCRIPT_PATH=$(dirname `which $0`)
REPO=$1

HGRC="$SCRIPT_PATH/$REPO/.hg/hgrc"
CURRENT=`pwd`
ABSOLUTE=$(cd $SCRIPT_PATH; pwd)
HOOKPATH=$(cd $ABSOLUTE/../../../src/hg/bash; pwd)
HOOK=$HOOKPATH/$2.sh

cd $CURRENT

if [ ! -f $HGRC ]; then
touch $HGRC
fi

echo "">> $HGRC
echo "[hooks]">> $HGRC
echo "$2 = $HOOK \"$3\" \"$4\" \"$5\"">> $HGRC
19 changes: 19 additions & 0 deletions test/hg/bash/change-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Cannot commit change to branch because repository is not defined"
exit 1
fi

if [ -z "$2" ]; then
echo "Cannot commit change to branch because file is not defined"
exit 1
fi

if [ ! -f "$1/$2" ]; then
touch $1/$2
fi

echo "text" >> $1/$2
hg add -R $1 $1/*
hg commit -R $1 --config ui.username=test -m "changed file from $0"
hg push -R $1
15 changes: 15 additions & 0 deletions test/hg/bash/clean-repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
SCRIPT_PATH=$(dirname `which $0`)
echo "Cleaning repositories"
if [ ! -z "$1" ]; then
rm -r $SCRIPT_PATH/$1
else
echo "Initial repository name was not defined"
fi

if [ ! -z "$2" ]; then
rm -r $SCRIPT_PATH/$2
else
echo "Clone repository name was not defined"
fi

9 changes: 9 additions & 0 deletions test/hg/bash/close-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ -z "$1" ]; then
echo "Cannot close branch because repository is not defined"
exit 1
fi

hg commit -R $1 --config ui.username=test --close-branch -m "closed"
hg push -R $1
16 changes: 16 additions & 0 deletions test/hg/bash/init-repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
if [ -z "$1" ]; then
echo "Initial repository name was not defined"
exit 1
fi

if [ -z "$2" ]; then
echo "Clone repository name was not defined"
exit 1
fi

SCRIPT_PATH=$(dirname `which $0`)

hg init $SCRIPT_PATH/$1
hg clone $SCRIPT_PATH/$1 $SCRIPT_PATH/$2

94 changes: 94 additions & 0 deletions test/hg/bash/test-incoming.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

checkReturnCode() {
if [ $1 -eq 1 ]; then
eval $2
echo "FAILURE"
exit 1
fi
}

REPO1=repository1
REPO2=repository2
SCRIPT_PATH=$(dirname `which $0`)
ABSOLUTE=$(cd $SCRIPT_PATH; pwd)
NEWBRANCH=$ABSOLUTE/newbranch
EXISTING=$ABSOLUTE/existing
CLOSED=$ABSOLUTE/closed
RESULT=0
CLEANUP="source $SCRIPT_PATH/clean-repos.sh $REPO1 $REPO2; rm $NEWBRANCH; rm $EXISTING; rm $CLOSED"

source $ABSOLUTE/init-repos.sh $REPO1 $REPO2
ret_code=$?
checkReturnCode $ret_code $CLEANUP

WRITE_RESULTS=$ABSOLUTE/write-file.sh

NP="$WRITE_RESULTS $NEWBRANCH"
NE="$WRITE_RESULTS $EXISTING"
NC="$WRITE_RESULTS $CLOSED"
source $SCRIPT_PATH/add-hook.sh $REPO1 incoming "$NP" "$NE" "$NC"
ret_code=$?
checkReturnCode $ret_code $CLEANUP


source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file"
ret_code=$?
checkReturnCode $ret_code $CLEANUP

source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file"
ret_code=$?
checkReturnCode $ret_code $CLEANUP

source $SCRIPT_PATH/close-branch.sh $ABSOLUTE/$REPO2
ret_code=$?
checkReturnCode $ret_code $CLEANUP

EXPECTED_NEW=("default")
EXPECTED_EXISTING=("default")
EXPECTED_CLOSED=("default")
I=0
while IFS='' read -r line || [[ -n "$line" ]]; do
linearr=($line)
if [ "${linearr[0]}" != "${EXPECTED_NEW[$I]}" ]; then
RESULT=1
fi
let "I++"
done < "$NEWBRANCH"
if [! $i -eq ${EXPECTED_NEW[@]} ]; then
RESULT=1
fi
I=0
while IFS='' read -r line || [[ -n "$line" ]]; do
linearr=($line)

if [ "${linearr[0]}" != "${EXPECTED_EXISTING[$I]}" ]; then
RESULT=1
fi
let "I++"
done < "$EXISTING"

if [! $i -eq ${EXPECTED_EXISTING[@]} ]; then
RESULT=1
fi

I=0
while IFS='' read -r line || [[ -n "$line" ]]; do
linearr=($line)

if [ "${linearr[0]}" != "${EXPECTED_CLOSED[$I]}" ]; then
RESULT=1
fi
let "I++"
done < "$CLOSED"

if [! $i -eq ${EXPECTED_CLOSED[@]} ]; then
RESULT=1
fi

eval $CLEANUP
if [ $RESULT -eq 1 ]; then
echo "FAILURE"
else
echo "SUCCESS"
fi
11 changes: 11 additions & 0 deletions test/hg/bash/write-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -z "$1" ]; then
echo File was not defined
fi

if [ ! -f "$1" ]; then
touch "$1"
fi

echo $2 $3 >> $1

0 comments on commit 7c03415

Please sign in to comment.