From 88871af85c01b6d738abf79c0cf659dacaf68779 Mon Sep 17 00:00:00 2001 From: Turmio Date: Tue, 30 May 2017 05:43:41 +0300 Subject: [PATCH] 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. Okay, it was failing. Does powershell handle bats differently? --- .appveyor.yml | 3 ++- .travis.yml | 3 ++- src/hg/bat/incoming.bat | 6 +++--- test/hg/bash/change-branch.sh | 15 +++++++++++++++ test/hg/bash/test-incoming.sh | 19 +++++++++++++------ test/hg/bat/change-branch.bat | 18 ++++++++++++++++++ test/hg/bat/test-incoming.bat | 11 ++++++----- 7 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 test/hg/bash/change-branch.sh create mode 100644 test/hg/bat/change-branch.bat diff --git a/.appveyor.yml b/.appveyor.yml index c785380..ab8f7a2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,5 @@ build: off test_script: - - test\hg\bat\test-incoming.bat \ No newline at end of file + - test\hg\bat\test-incoming.bat + - test\hg\bat\test-incoming.bat branch-with-dash \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index d239856..f2e3f94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ install: true script: - chmod +x test/hg/bash/test-incoming.sh - - ./test/hg/bash/test-incoming.sh \ No newline at end of file + - ./test/hg/bash/test-incoming.sh + - ./test/hg/bash/test-incoming.sh with-dash diff --git a/src/hg/bat/incoming.bat b/src/hg/bat/incoming.bat index 611ce33..51f79f2 100644 --- a/src/hg/bat/incoming.bat +++ b/src/hg/bat/incoming.bat @@ -8,18 +8,18 @@ set closed=hg log -r "closed() and branch(%BRANCH%)" --template "{node}\n" FOR /F "tokens=*" %%f in ('%first%') do SET INITIAL=%%f rem On new branch if "%HG_NODE%"=="%INITIAL%" ( -if not "%~1"=="" call %~1 %BRANCH% %HG_NODE% +if not "%~1"=="" call %~1 "%BRANCH%" "%HG_NODE%" goto done ) FOR /F "tokens=*" %%f in ('%closed%') do SET CLOSE=%%f rem On close branch if "%HG_NODE%"=="%CLOSE%" ( -if not "%~3"=="" call %~3 %BRANCH% %HG_NODE% +if not "%~3"=="" call %~3 "%BRANCH%" "%HG_NODE%" goto done ) rem On existing branch -if not "%~2"=="" call %~2 %BRANCH% %HG_NODE% +if not "%~2"=="" call %~2 "%BRANCH%" "%HG_NODE%" goto done :done \ No newline at end of file diff --git a/test/hg/bash/change-branch.sh b/test/hg/bash/change-branch.sh new file mode 100644 index 0000000..68c8ce7 --- /dev/null +++ b/test/hg/bash/change-branch.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ -z $2 ]; then + echo "ERROR: Branch name not given. Cannot create branch without name." + exit 1 +fi + +CURRENT=$(hg branch) + +if [ "$CURRENT" = "$1" ]; then + echo "WARN: Already in given branch." +fi + +hg -R $1 branch $2 +hg -R $1 push -f diff --git a/test/hg/bash/test-incoming.sh b/test/hg/bash/test-incoming.sh index 5683e87..1d13121 100644 --- a/test/hg/bash/test-incoming.sh +++ b/test/hg/bash/test-incoming.sh @@ -8,6 +8,12 @@ checkReturnCode() { fi } +BRANCH=$1 + +if [ -z $BRANCH ]; then + BRANCH=default +fi + REPO1=repository1 REPO2=repository2 SCRIPT_PATH=$(dirname `which $0`) @@ -31,6 +37,7 @@ source $SCRIPT_PATH/add-hook.sh $REPO1 incoming "$NP" "$NE" "$NC" ret_code=$? checkReturnCode $ret_code $CLEANUP +source $SCRIPT_PATH/change-branch.sh $ABSOLUTE/$REPO2 $BRANCH source $SCRIPT_PATH/change-file.sh $ABSOLUTE/$REPO2 "file" ret_code=$? @@ -44,9 +51,9 @@ source $SCRIPT_PATH/close-branch.sh $ABSOLUTE/$REPO2 ret_code=$? checkReturnCode $ret_code $CLEANUP -EXPECTED_NEW=("default") -EXPECTED_EXISTING=("default") -EXPECTED_CLOSED=("default") +EXPECTED_NEW=("$BRANCH") +EXPECTED_EXISTING=("$BRANCH") +EXPECTED_CLOSED=("$BRANCH") I=0 while IFS='' read -r line || [[ -n "$line" ]]; do linearr=($line) @@ -55,7 +62,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do fi let "I++" done < "$NEWBRANCH" -if [! $i -eq ${EXPECTED_NEW[@]} ]; then +if [ "$I" -ne "${#EXPECTED_NEW[@]}" ]; then RESULT=1 fi I=0 @@ -68,7 +75,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do let "I++" done < "$EXISTING" -if [! $i -eq ${EXPECTED_EXISTING[@]} ]; then +if [ "$I" -ne "${#EXPECTED_EXISTING[@]}" ]; then RESULT=1 fi @@ -82,7 +89,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do let "I++" done < "$CLOSED" -if [! $i -eq ${EXPECTED_CLOSED[@]} ]; then +if [ "$I" -ne "${#EXPECTED_CLOSED[@]}" ]; then RESULT=1 fi diff --git a/test/hg/bat/change-branch.bat b/test/hg/bat/change-branch.bat new file mode 100644 index 0000000..ada9e41 --- /dev/null +++ b/test/hg/bat/change-branch.bat @@ -0,0 +1,18 @@ +IF [%2] == [] GOTO BranchNotSet + + +for /f %%i in ('hg -R %1 branch') do set current=%%i + +if [%2] == [%current%] GOTO Ready + +hg -R %1 branch %2 +hg -R %1 push -f +GOTO Ready + + +:BranchNotSet +echo "ERROR: Cannot change branch if it is not defined" +exit 1 + +:Ready + diff --git a/test/hg/bat/test-incoming.bat b/test/hg/bat/test-incoming.bat index e6a39d8..decc760 100644 --- a/test/hg/bat/test-incoming.bat +++ b/test/hg/bat/test-incoming.bat @@ -1,6 +1,7 @@ @ECHO OFF setlocal EnableDelayedExpansion - +set branch=%1 +if [%branch%] == [] set branch=default set result=0 set r1=repository1 set r2=repository2 @@ -17,16 +18,16 @@ if errorlevel 1 ( set result=1 goto CLEANUP ) - +call %~dp0\change-branch.bat %r2% %branch% call %~dp0\change-file.bat %r2% file call %~dp0\change-file.bat %r2% file call %~dp0\close-branch.bat %r2% rem Verify results echo Starting to verify results -set expectedNew[0]=default -set expectedExisting[0]=default -set expectedClose[0]=default +set expectedNew[0]=%branch% +set expectedExisting[0]=%branch% +set expectedClose[0]=%branch% rem TODO: calculate from above set countNew=1