Skip to content

Commit 7c03415

Browse files
authored
Merge pull request #1 from Turmio/incoming-linux
Incoming linux
2 parents c6b21b7 + 2c74907 commit 7c03415

File tree

9 files changed

+232
-1
lines changed

9 files changed

+232
-1
lines changed

.travis.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
language: python
1+
language: python
2+
3+
branches:
4+
only:
5+
- gh-pages
6+
- /.*/
7+
8+
install: true
9+
10+
script:
11+
- chmod +x test/hg/bash/test-incoming.sh
12+
- ./test/hg/bash/test-incoming.sh

src/hg/bash/incoming.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
ON_NEW=$1
4+
ON_EXISTING=$2
5+
ON_CLOSED=$3
6+
7+
REPO=`echo $(echo "$HG_URL" | sed "s/^file://g")`
8+
9+
#get branch
10+
BRANCH=`hg log --rev $HG_NODE --template "{branch}\n"`
11+
#first commit to branch
12+
FIRST=`hg log -r "min(branch($BRANCH))" --template "{node}\n"`
13+
#is closed
14+
CLOSED=`hg log -r "closed() and branch($BRANCH)" --template "{node}\n" | awk 'NR==1'`
15+
16+
if [ "$HG_NODE" = "$FIRST" ]; then
17+
CMD="$ON_NEW $BRANCH $HG_NODE"
18+
eval $CMD
19+
elif [ "$HG_NODE" = "$CLOSED" ]; then
20+
CMD="$ON_CLOSED $BRANCH $HG_NODE"
21+
eval $CMD
22+
else
23+
CMD="$ON_EXISTING $BRANCH $HG_NODE"
24+
eval $CMD
25+
fi

test/hg/bash/add-hook.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Cannot add hook because repository is not defined"
5+
exit 1
6+
fi
7+
8+
if [ -z "$2" ]; then
9+
echo "Cannot add hook because hook is not defined"
10+
exit 1
11+
fi
12+
13+
14+
SCRIPT_PATH=$(dirname `which $0`)
15+
REPO=$1
16+
17+
HGRC="$SCRIPT_PATH/$REPO/.hg/hgrc"
18+
CURRENT=`pwd`
19+
ABSOLUTE=$(cd $SCRIPT_PATH; pwd)
20+
HOOKPATH=$(cd $ABSOLUTE/../../../src/hg/bash; pwd)
21+
HOOK=$HOOKPATH/$2.sh
22+
23+
cd $CURRENT
24+
25+
if [ ! -f $HGRC ]; then
26+
touch $HGRC
27+
fi
28+
29+
echo "">> $HGRC
30+
echo "[hooks]">> $HGRC
31+
echo "$2 = $HOOK \"$3\" \"$4\" \"$5\"">> $HGRC

test/hg/bash/change-file.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
if [ -z "$1" ]; then
3+
echo "Cannot commit change to branch because repository is not defined"
4+
exit 1
5+
fi
6+
7+
if [ -z "$2" ]; then
8+
echo "Cannot commit change to branch because file is not defined"
9+
exit 1
10+
fi
11+
12+
if [ ! -f "$1/$2" ]; then
13+
touch $1/$2
14+
fi
15+
16+
echo "text" >> $1/$2
17+
hg add -R $1 $1/*
18+
hg commit -R $1 --config ui.username=test -m "changed file from $0"
19+
hg push -R $1

test/hg/bash/clean-repos.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
SCRIPT_PATH=$(dirname `which $0`)
3+
echo "Cleaning repositories"
4+
if [ ! -z "$1" ]; then
5+
rm -r $SCRIPT_PATH/$1
6+
else
7+
echo "Initial repository name was not defined"
8+
fi
9+
10+
if [ ! -z "$2" ]; then
11+
rm -r $SCRIPT_PATH/$2
12+
else
13+
echo "Clone repository name was not defined"
14+
fi
15+

test/hg/bash/close-branch.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
if [ -z "$1" ]; then
4+
echo "Cannot close branch because repository is not defined"
5+
exit 1
6+
fi
7+
8+
hg commit -R $1 --config ui.username=test --close-branch -m "closed"
9+
hg push -R $1

test/hg/bash/init-repos.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
if [ -z "$1" ]; then
3+
echo "Initial repository name was not defined"
4+
exit 1
5+
fi
6+
7+
if [ -z "$2" ]; then
8+
echo "Clone repository name was not defined"
9+
exit 1
10+
fi
11+
12+
SCRIPT_PATH=$(dirname `which $0`)
13+
14+
hg init $SCRIPT_PATH/$1
15+
hg clone $SCRIPT_PATH/$1 $SCRIPT_PATH/$2
16+

test/hg/bash/test-incoming.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
checkReturnCode() {
4+
if [ $1 -eq 1 ]; then
5+
eval $2
6+
echo "FAILURE"
7+
exit 1
8+
fi
9+
}
10+
11+
REPO1=repository1
12+
REPO2=repository2
13+
SCRIPT_PATH=$(dirname `which $0`)
14+
ABSOLUTE=$(cd $SCRIPT_PATH; pwd)
15+
NEWBRANCH=$ABSOLUTE/newbranch
16+
EXISTING=$ABSOLUTE/existing
17+
CLOSED=$ABSOLUTE/closed
18+
RESULT=0
19+
CLEANUP="source $SCRIPT_PATH/clean-repos.sh $REPO1 $REPO2; rm $NEWBRANCH; rm $EXISTING; rm $CLOSED"
20+
21+
source $ABSOLUTE/init-repos.sh $REPO1 $REPO2
22+
ret_code=$?
23+
checkReturnCode $ret_code $CLEANUP
24+
25+
WRITE_RESULTS=$ABSOLUTE/write-file.sh
26+
27+
NP="$WRITE_RESULTS $NEWBRANCH"
28+
NE="$WRITE_RESULTS $EXISTING"
29+
NC="$WRITE_RESULTS $CLOSED"
30+
source $SCRIPT_PATH/add-hook.sh $REPO1 incoming "$NP" "$NE" "$NC"
31+
ret_code=$?
32+
checkReturnCode $ret_code $CLEANUP
33+
34+
35+
source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file"
36+
ret_code=$?
37+
checkReturnCode $ret_code $CLEANUP
38+
39+
source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file"
40+
ret_code=$?
41+
checkReturnCode $ret_code $CLEANUP
42+
43+
source $SCRIPT_PATH/close-branch.sh $ABSOLUTE/$REPO2
44+
ret_code=$?
45+
checkReturnCode $ret_code $CLEANUP
46+
47+
EXPECTED_NEW=("default")
48+
EXPECTED_EXISTING=("default")
49+
EXPECTED_CLOSED=("default")
50+
I=0
51+
while IFS='' read -r line || [[ -n "$line" ]]; do
52+
linearr=($line)
53+
if [ "${linearr[0]}" != "${EXPECTED_NEW[$I]}" ]; then
54+
RESULT=1
55+
fi
56+
let "I++"
57+
done < "$NEWBRANCH"
58+
if [! $i -eq ${EXPECTED_NEW[@]} ]; then
59+
RESULT=1
60+
fi
61+
I=0
62+
while IFS='' read -r line || [[ -n "$line" ]]; do
63+
linearr=($line)
64+
65+
if [ "${linearr[0]}" != "${EXPECTED_EXISTING[$I]}" ]; then
66+
RESULT=1
67+
fi
68+
let "I++"
69+
done < "$EXISTING"
70+
71+
if [! $i -eq ${EXPECTED_EXISTING[@]} ]; then
72+
RESULT=1
73+
fi
74+
75+
I=0
76+
while IFS='' read -r line || [[ -n "$line" ]]; do
77+
linearr=($line)
78+
79+
if [ "${linearr[0]}" != "${EXPECTED_CLOSED[$I]}" ]; then
80+
RESULT=1
81+
fi
82+
let "I++"
83+
done < "$CLOSED"
84+
85+
if [! $i -eq ${EXPECTED_CLOSED[@]} ]; then
86+
RESULT=1
87+
fi
88+
89+
eval $CLEANUP
90+
if [ $RESULT -eq 1 ]; then
91+
echo "FAILURE"
92+
else
93+
echo "SUCCESS"
94+
fi

test/hg/bash/write-file.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo File was not defined
5+
fi
6+
7+
if [ ! -f "$1" ]; then
8+
touch "$1"
9+
fi
10+
11+
echo $2 $3 >> $1

0 commit comments

Comments
 (0)