Skip to content

Commit

Permalink
fix(1262): Always update submodule after clone (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
catto authored and minzcmu committed Sep 7, 2018
1 parent 3aa92ee commit 4b3fa27
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,17 @@ class GithubScm extends Scm {
command.push(`${gitWrapper} "git fetch origin ${prRef}"`);
// Merge a pull request with pipeline branch
command.push(`${gitWrapper} "git merge ${config.sha}"`);
// Init & Update submodule
command.push(`${gitWrapper} "git submodule init"`);
command.push(`${gitWrapper} "git submodule update --recursive"`);
command.push(`export GIT_BRANCH=origin/refs/${prRef}`);
} else {
command.push(`export GIT_BRANCH=origin/${branch}`);
}

if (!config.manifest) {
// Init & Update submodule only when sd-repo is not used
command.push(`${gitWrapper} "git submodule init"`);
command.push(`${gitWrapper} "git submodule update --recursive"`);
}

return {
name: 'sd-checkout-code',
command: command.join(' && ')
Expand Down
2 changes: 1 addition & 1 deletion test/data/childCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export CONFIG_URL=git@github.com:screwdriver-cd/parent-to-guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export CONFIG_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/parent-to-guide; else export CONFIG_URL=https://github.com/screwdriver-cd/parent-to-guide; fi && export SD_CONFIG_DIR=$SD_ROOT_DIR/config && echo Cloning external config repo github.com/screwdriver-cd/parent-to-guide && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch master $CONFIG_URL $SD_CONFIG_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git -C $SD_CONFIG_DIR reset --hard 54321 --\" && echo Reset external config repo to 54321 && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 && export GIT_BRANCH=origin/branchName"
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export CONFIG_URL=git@github.com:screwdriver-cd/parent-to-guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export CONFIG_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/parent-to-guide; else export CONFIG_URL=https://github.com/screwdriver-cd/parent-to-guide; fi && export SD_CONFIG_DIR=$SD_ROOT_DIR/config && echo Cloning external config repo github.com/screwdriver-cd/parent-to-guide && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch master $CONFIG_URL $SD_CONFIG_DIR\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git -C $SD_CONFIG_DIR reset --hard 54321 --\" && echo Reset external config repo to 54321 && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 && export GIT_BRANCH=origin/branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/commands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 && export GIT_BRANCH=origin/branchName"
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 && export GIT_BRANCH=origin/branchName && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/commitBranchCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch commitBranch && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch commitBranch $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 && export GIT_BRANCH=origin/commitBranch"
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch commitBranch && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git clone --recursive --quiet --progress --branch commitBranch $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 && export GIT_BRANCH=origin/commitBranch && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/customPrCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name pqrs\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@my.email.com\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 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\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\" && export GIT_BRANCH=origin/refs/pull/3/head:pr"
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name pqrs\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@my.email.com\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 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 && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/prCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 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\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\" && export GIT_BRANCH=origin/refs/pull/3/head:pr"
"command": "echo Exporting environment variables && 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 && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && 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 --global user.name sd-buildbot\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git config --global user.email dev-null@screwdriver.cd\" && echo Cloning github.com/screwdriver-cd/guide, on branch branchName && $(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 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 && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule init\" && $(if git --version > /dev/null 2>&1; then echo 'eval'; else echo 'sd-step exec core/git'; fi) \"git submodule update --recursive\""
}

0 comments on commit 4b3fa27

Please sign in to comment.