Skip to content

Commit 730d816

Browse files
committed
Test with branch as parameter. Default branch name is default
Bash with dash was working but there were no test for branch name with dash It seems that bat was also working. Odd.
1 parent 7c03415 commit 730d816

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

.appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build: off
22

33
test_script:
4-
- test\hg\bat\test-incoming.bat
4+
- test\hg\bat\test-incoming.bat
5+
- test\hg\bat\test-incoming.bat branch-with-dash

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ install: true
99

1010
script:
1111
- chmod +x test/hg/bash/test-incoming.sh
12-
- ./test/hg/bash/test-incoming.sh
12+
- ./test/hg/bash/test-incoming.sh
13+
- ./test/hg/bash/test-incoming.sh with-dash

test/hg/bash/change-branch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
if [ -z $2 ]; then
4+
echo "ERROR: Branch name not given. Cannot create branch without name."
5+
exit 1
6+
fi
7+
8+
CURRENT=$(hg branch)
9+
10+
if [ "$CURRENT" = "$1" ]; then
11+
echo "WARN: Already in given branch."
12+
fi
13+
14+
hg -R $1 branch $2
15+
hg -R $1 push -f

test/hg/bash/test-incoming.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ checkReturnCode() {
88
fi
99
}
1010

11+
BRANCH=$1
12+
13+
if [ -z $BRANCH ]; then
14+
BRANCH=default
15+
fi
16+
1117
REPO1=repository1
1218
REPO2=repository2
1319
SCRIPT_PATH=$(dirname `which $0`)
@@ -31,6 +37,7 @@ source $SCRIPT_PATH/add-hook.sh $REPO1 incoming "$NP" "$NE" "$NC"
3137
ret_code=$?
3238
checkReturnCode $ret_code $CLEANUP
3339

40+
source $SCRIPT_PATH/change-branch.sh $ABSOLUTE/$REPO2 $BRANCH
3441

3542
source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file"
3643
ret_code=$?
@@ -44,9 +51,9 @@ source $SCRIPT_PATH/close-branch.sh $ABSOLUTE/$REPO2
4451
ret_code=$?
4552
checkReturnCode $ret_code $CLEANUP
4653

47-
EXPECTED_NEW=("default")
48-
EXPECTED_EXISTING=("default")
49-
EXPECTED_CLOSED=("default")
54+
EXPECTED_NEW=("$BRANCH")
55+
EXPECTED_EXISTING=("$BRANCH")
56+
EXPECTED_CLOSED=("$BRANCH")
5057
I=0
5158
while IFS='' read -r line || [[ -n "$line" ]]; do
5259
linearr=($line)
@@ -55,7 +62,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
5562
fi
5663
let "I++"
5764
done < "$NEWBRANCH"
58-
if [! $i -eq ${EXPECTED_NEW[@]} ]; then
65+
if [ "$I" -ne "${#EXPECTED_NEW[@]}" ]; then
5966
RESULT=1
6067
fi
6168
I=0
@@ -68,7 +75,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
6875
let "I++"
6976
done < "$EXISTING"
7077

71-
if [! $i -eq ${EXPECTED_EXISTING[@]} ]; then
78+
if [ "$I" -ne "${#EXPECTED_EXISTING[@]}" ]; then
7279
RESULT=1
7380
fi
7481

@@ -82,7 +89,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
8289
let "I++"
8390
done < "$CLOSED"
8491

85-
if [! $i -eq ${EXPECTED_CLOSED[@]} ]; then
92+
if [ "$I" -ne "${#EXPECTED_CLOSED[@]}" ]; then
8693
RESULT=1
8794
fi
8895

test/hg/bat/change-branch.bat

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
IF [%2] == [] GOTO BranchNotSet
2+
3+
4+
for /f %%i in ('hg -R %1 branch') do set current=%%i
5+
6+
if [%2] == [%current%] GOTO Ready
7+
8+
hg -R %1 branch %2
9+
hg -R %1 push -f
10+
GOTO Ready
11+
12+
13+
:BranchNotSet
14+
echo "ERROR: Cannot change branch if it is not defined"
15+
exit 1
16+
17+
:Ready
18+

test/hg/bat/test-incoming.bat

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@ECHO OFF
22
setlocal EnableDelayedExpansion
3-
3+
set branch=%1
4+
if [%branch%] == [] set branch=default
45
set result=0
56
set r1=repository1
67
set r2=repository2
@@ -17,16 +18,16 @@ if errorlevel 1 (
1718
set result=1
1819
goto CLEANUP
1920
)
20-
21+
call %~dp0\change-branch.bat %r2% %branch%
2122
call %~dp0\change-file.bat %r2% file
2223
call %~dp0\change-file.bat %r2% file
2324
call %~dp0\close-branch.bat %r2%
2425

2526
rem Verify results
2627
echo Starting to verify results
27-
set expectedNew[0]=default
28-
set expectedExisting[0]=default
29-
set expectedClose[0]=default
28+
set expectedNew[0]=%branch%
29+
set expectedExisting[0]=%branch%
30+
set expectedClose[0]=%branch%
3031

3132
rem TODO: calculate from above
3233
set countNew=1

0 commit comments

Comments
 (0)