From 912209fb30ad6000a58e344fa92542e08a084cb2 Mon Sep 17 00:00:00 2001 From: rnakayam Date: Wed, 4 Apr 2018 14:21:57 +0900 Subject: [PATCH] fix: specify branch explicitly to git reset command --- index.js | 2 +- test/data/commands.json | 2 +- test/data/customPrCommands.json | 2 +- test/data/prCommands.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c7c793f..df66a7d 100644 --- a/index.js +++ b/index.js @@ -291,7 +291,7 @@ class GithubScm extends Scm { + `"git clone --recursive --quiet --progress --branch ${config.branch} ` + '$SCM_URL $SD_SOURCE_DIR"'); // Reset to SHA - command.push(`${gitWrapper} "git reset --hard ${checkoutRef}"`); + command.push(`${gitWrapper} "git reset --hard ${checkoutRef} --"`); command.push(`echo Reset to ${checkoutRef}`); // Set config command.push('echo Setting user name and user email'); diff --git a/test/data/commands.json b/test/data/commands.json index ef6a340..08296b3 100644 --- a/test/data/commands.json +++ b/test/data/commands.json @@ -1,4 +1,4 @@ { "name": "sd-checkout-code", - "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard 12345\" && echo Reset to 12345 && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@screwdriver.cd\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && export GIT_BRANCH=origin/branchName" + "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard 12345 --\" && echo Reset to 12345 && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@screwdriver.cd\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && export GIT_BRANCH=origin/branchName" } diff --git a/test/data/customPrCommands.json b/test/data/customPrCommands.json index 8bd4527..063ae10 100644 --- a/test/data/customPrCommands.json +++ b/test/data/customPrCommands.json @@ -1,4 +1,4 @@ { "name": "sd-checkout-code", - "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard branchName\" && echo Reset to branchName && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name pqrs\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@my.email.com\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Fetching PR and merging with branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git fetch origin pull/3/head:pr\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr" + "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard branchName --\" && echo Reset to branchName && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name pqrs\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@my.email.com\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Fetching PR and merging with branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git fetch origin pull/3/head:pr\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr" } diff --git a/test/data/prCommands.json b/test/data/prCommands.json index e926678..951f949 100644 --- a/test/data/prCommands.json +++ b/test/data/prCommands.json @@ -1,4 +1,4 @@ { "name": "sd-checkout-code", - "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard branchName\" && echo Reset to branchName && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@screwdriver.cd\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Fetching PR and merging with branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git fetch origin pull/3/head:pr\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr" + "command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git reset --hard branchName --\" && echo Reset to branchName && echo Setting user name and user email && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config user.email dev-null@screwdriver.cd\" && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Fetching PR and merging with branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git fetch origin pull/3/head:pr\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr" }