diff --git a/__tests__/utils/command.test.ts b/__tests__/utils/command.test.ts index 8d9c691..ce46ff4 100644 --- a/__tests__/utils/command.test.ts +++ b/__tests__/utils/command.test.ts @@ -108,6 +108,7 @@ describe('clone', () => { 'git fetch --no-tags origin \'refs/heads/hello-world/test-branch:refs/remotes/origin/hello-world/test-branch\' || :', 'git reset --hard || :', 'git checkout -b hello-world/test-branch origin/hello-world/test-branch || :', + 'git checkout hello-world/test-branch || :', ]); stdoutCalledWith(mockStdout, [ '::group::Fetching...', @@ -122,6 +123,8 @@ describe('clone', () => { '::group::Switching branch to [hello-world/test-branch]...', '[command]git checkout -b hello-world/test-branch origin/hello-world/test-branch', ' >> stdout', + '[command]git checkout hello-world/test-branch', + ' >> stdout', ]); }); }); @@ -158,12 +161,11 @@ describe('checkBranch', () => { }))).toBe(false); execCalledWith(mockExec, [ - 'git rev-parse --abbrev-ref HEAD || :', - 'git checkout hello-world/test-branch || :', 'git rev-parse --abbrev-ref HEAD || :', 'git remote add origin \'https://octocat:test-token@github.com/hello/world.git\' > /dev/null 2>&1 || :', 'git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\' || :', 'git checkout -b feature/new-feature origin/feature/new-feature || :', + 'git checkout feature/new-feature || :', 'git checkout -b hello-world/test-branch', 'ls -la', ]); @@ -368,6 +370,7 @@ describe('getChangedFiles', () => { '::endgroup::', '::group::Switching branch to [hello-world/test-branch]...', '[command]git checkout -b hello-world/test-branch origin/hello-world/test-branch', + '[command]git checkout hello-world/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> hello-world/test-branch', '[command]git merge --no-edit origin/hello-world/test-branch', @@ -452,6 +455,7 @@ describe('getChangedFiles', () => { '::endgroup::', '::group::Switching branch to [hello-world/test-branch]...', '[command]git checkout -b hello-world/test-branch origin/hello-world/test-branch', + '[command]git checkout hello-world/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> hello-world/test-branch', '[command]git merge --no-edit origin/hello-world/test-branch', @@ -565,6 +569,7 @@ describe('getChangedFiles', () => { '::endgroup::', '::group::Switching branch to [hello-world/test-branch]...', '[command]git checkout -b hello-world/test-branch origin/hello-world/test-branch', + '[command]git checkout hello-world/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> hello-world/test-branch', '[command]git merge --no-edit origin/hello-world/test-branch', @@ -874,6 +879,7 @@ describe('resolveConflicts', () => { 'git remote add origin \'https://octocat:test-token@github.com/hello/world.git\' > /dev/null 2>&1 || :', 'git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\' || :', 'git checkout -b feature/new-feature origin/feature/new-feature || :', + 'git checkout feature/new-feature || :', 'git checkout -b hello-world/test-branch', 'yarn upgrade', 'git add --all', @@ -927,6 +933,7 @@ describe('resolveConflicts', () => { 'git remote add origin \'https://octocat:test-token@github.com/hello/world.git\' > /dev/null 2>&1 || :', 'git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\' || :', 'git checkout -b feature/new-feature origin/feature/new-feature || :', + 'git checkout feature/new-feature || :', 'git checkout -b hello-world/test-branch', 'yarn upgrade', 'git add --all', diff --git a/__tests__/utils/process1.test.ts b/__tests__/utils/process1.test.ts index 89a40aa..3ce07f8 100644 --- a/__tests__/utils/process1.test.ts +++ b/__tests__/utils/process1.test.ts @@ -120,6 +120,7 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -200,8 +201,6 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-21031067', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -212,6 +211,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\'', '[command]git checkout -b feature/new-feature origin/feature/new-feature', + '[command]git checkout feature/new-feature', '[command]git checkout -b Hello-World/test-21031067', '[command]ls -la', '::endgroup::', @@ -285,8 +285,6 @@ describe('execute', () => { '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', ' >> stdout', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> stdout', '[command]git checkout Hello-World/test-21031067', ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', @@ -300,6 +298,8 @@ describe('execute', () => { ' >> stdout', '[command]git checkout -b feature/new-feature origin/feature/new-feature', ' >> stdout', + '[command]git checkout feature/new-feature', + ' >> stdout', '[command]git checkout -b Hello-World/test-21031067', ' >> stdout', '[command]ls -la', @@ -427,6 +427,7 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -633,8 +634,6 @@ describe('execute', () => { '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', ' >> stdout', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> stdout', '[command]git checkout Hello-World/test-21031067', ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', @@ -648,6 +647,8 @@ describe('execute', () => { ' >> stdout', '[command]git checkout -b feature/new-feature origin/feature/new-feature', ' >> stdout', + '[command]git checkout feature/new-feature', + ' >> stdout', '[command]git checkout -b Hello-World/test-21031067', ' >> stdout', '[command]ls -la', @@ -699,6 +700,7 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [test/change]...', '[command]git checkout -b test/change origin/test/change', + '[command]git checkout test/change', '[command]git rev-parse --abbrev-ref HEAD', ' >> test/change', '[command]git merge --no-edit origin/test/change', diff --git a/__tests__/utils/process2.test.ts b/__tests__/utils/process2.test.ts index e1f24ba..585782d 100644 --- a/__tests__/utils/process2.test.ts +++ b/__tests__/utils/process2.test.ts @@ -120,8 +120,6 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-21031067', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -132,6 +130,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\'', '[command]git checkout -b feature/new-feature origin/feature/new-feature', + '[command]git checkout feature/new-feature', '[command]git checkout -b Hello-World/test-21031067', '[command]ls -la', '::endgroup::', @@ -205,8 +204,6 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-21031067', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -217,6 +214,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\'', '[command]git checkout -b feature/new-feature origin/feature/new-feature', + '[command]git checkout feature/new-feature', '[command]git checkout -b Hello-World/test-21031067', '[command]ls -la', '::endgroup::', @@ -287,8 +285,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [test/test-1]...', '[command]git checkout -b test/test-1 origin/test/test-1', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout test/test-1', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -298,6 +294,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/change/new-topic1:refs/remotes/origin/change/new-topic1\'', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git checkout -b test/test-1', '[command]ls -la', '> Running commands...', @@ -316,8 +313,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [test/test-2]...', '[command]git checkout -b test/test-2 origin/test/test-2', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout test/test-2', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -327,6 +322,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/change/new-topic2:refs/remotes/origin/change/new-topic2\'', '[command]git checkout -b change/new-topic2 origin/change/new-topic2', + '[command]git checkout change/new-topic2', '[command]git checkout -b test/test-2', '[command]ls -la', '> Running commands...', @@ -393,8 +389,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [test/test-branch]...', '[command]git checkout -b test/test-branch origin/test/test-branch', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout test/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -404,6 +398,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/change/new-topic1:refs/remotes/origin/change/new-topic1\'', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git checkout -b test/test-branch', '[command]ls -la', '> Running commands...', @@ -484,6 +479,7 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -550,6 +546,7 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [test]...', '[command]git checkout -b test origin/test', + '[command]git checkout test', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', '[command]git merge --no-edit origin/test', @@ -620,6 +617,7 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [feature/new-feature]...', '[command]git checkout -b feature/new-feature origin/feature/new-feature', + '[command]git checkout feature/new-feature', '[command]git rev-parse --abbrev-ref HEAD', ' >> feature/new-feature', '[command]git merge --no-edit origin/feature/new-feature', @@ -710,6 +708,7 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -804,8 +803,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [Hello-World/test-branch]...', '[command]git checkout -b Hello-World/test-branch origin/Hello-World/test-branch', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -815,6 +812,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-topic3:refs/remotes/origin/feature/new-topic3\'', '[command]git checkout -b feature/new-topic3 origin/feature/new-topic3', + '[command]git checkout feature/new-topic3', '[command]git checkout -b Hello-World/test-branch', '[command]ls -la', '> Running commands...', @@ -890,6 +888,8 @@ describe('execute', () => { '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', ' >> stdout', + '[command]git checkout change/new-topic1', + ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -972,6 +972,8 @@ describe('execute', () => { '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', ' >> stdout', + '[command]git checkout change/new-topic1', + ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -1066,8 +1068,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [master]...', '[command]git checkout -b master origin/master', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout master', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -1077,6 +1077,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\'', '[command]git checkout -b master origin/master', + '[command]git checkout master', '[command]git checkout -b master', '[command]ls -la', '> Running commands...', @@ -1146,8 +1147,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [Hello-World/test-branch]...', '[command]git checkout -b Hello-World/test-branch origin/Hello-World/test-branch', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-branch', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -1157,6 +1156,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-topic3:refs/remotes/origin/feature/new-topic3\'', '[command]git checkout -b feature/new-topic3 origin/feature/new-topic3', + '[command]git checkout feature/new-topic3', '[command]git checkout -b Hello-World/test-branch', '[command]ls -la', '> Running commands...', @@ -1226,6 +1226,7 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', + '[command]git checkout change/new-topic1', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -1253,8 +1254,6 @@ describe('execute', () => { '[command]git reset --hard', '> Switching branch to [change/test-0]...', '[command]git checkout -b change/test-0 origin/change/test-0', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> change/new-topic1', '[command]git checkout change/test-0', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', @@ -1264,6 +1263,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\'', '[command]git checkout -b master origin/master', + '[command]git checkout master', '[command]git checkout -b change/test-0', '[command]ls -la', '> Running commands...', @@ -1329,8 +1329,6 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> test', '[command]git checkout Hello-World/test-21031067', '[command]git rev-parse --abbrev-ref HEAD', ' >> test', @@ -1341,6 +1339,7 @@ describe('execute', () => { '[command]git remote add origin', '[command]git fetch --no-tags origin \'refs/heads/feature/new-feature:refs/remotes/origin/feature/new-feature\'', '[command]git checkout -b feature/new-feature origin/feature/new-feature', + '[command]git checkout feature/new-feature', '[command]git checkout -b Hello-World/test-21031067', '[command]ls -la', '::endgroup::', @@ -1432,6 +1431,7 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [test/change]...', '[command]git checkout -b test/change origin/test/change', + '[command]git checkout test/change', '[command]git rev-parse --abbrev-ref HEAD', ' >> test/change', '[command]git merge --no-edit origin/test/change', @@ -1490,6 +1490,7 @@ describe('execute', () => { '::endgroup::', '::group::Switching branch to [test/change]...', '[command]git checkout -b test/change origin/test/change', + '[command]git checkout test/change', '[command]git rev-parse --abbrev-ref HEAD', ' >> test/change', '[command]git merge --no-edit origin/test/change', @@ -1554,8 +1555,6 @@ describe('execute', () => { '::group::Switching branch to [Hello-World/test-21031067]...', '[command]git checkout -b Hello-World/test-21031067 origin/Hello-World/test-21031067', ' >> stdout', - '[command]git rev-parse --abbrev-ref HEAD', - ' >> stdout', '[command]git checkout Hello-World/test-21031067', ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', @@ -1569,6 +1568,8 @@ describe('execute', () => { ' >> stdout', '[command]git checkout -b feature/new-feature origin/feature/new-feature', ' >> stdout', + '[command]git checkout feature/new-feature', + ' >> stdout', '[command]git checkout -b Hello-World/test-21031067', ' >> stdout', '[command]ls -la', @@ -1664,6 +1665,8 @@ describe('execute', () => { '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', ' >> stdout', + '[command]git checkout change/new-topic1', + ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', @@ -1763,6 +1766,8 @@ describe('execute', () => { '> Switching branch to [change/new-topic1]...', '[command]git checkout -b change/new-topic1 origin/change/new-topic1', ' >> stdout', + '[command]git checkout change/new-topic1', + ' >> stdout', '[command]git rev-parse --abbrev-ref HEAD', ' >> change/new-topic1', '[command]git merge --no-edit origin/change/new-topic1', diff --git a/package.json b/package.json index 8b901ca..b4c1041 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@technote-space/github-action-pr-helper", - "version": "2.0.2", + "version": "2.0.3", "description": "PullRequest Helper for GitHub Actions.", "keywords": [ "github", @@ -37,7 +37,7 @@ "@actions/core": "^1.2.6", "@actions/github": "^4.0.0", "@technote-space/filter-github-action": "^0.5.8", - "@technote-space/github-action-helper": "^4.3.1", + "@technote-space/github-action-helper": "^4.3.2", "moment": "^2.29.1" }, "devDependencies": { diff --git a/src/utils/command.ts b/src/utils/command.ts index 7b56f99..3b312ac 100644 --- a/src/utils/command.ts +++ b/src/utils/command.ts @@ -50,18 +50,8 @@ export const clone = async(helper: GitHelper, logger: Logger, octokit: Octokit, }; export const checkBranch = async(helper: GitHelper, logger: Logger, octokit: Octokit, context: ActionContext): Promise => { - let clonedBranch = await helper.getCurrentBranchName(getWorkspace()); - const branchName = await getPrBranchName(helper, octokit, context); - if (branchName !== clonedBranch) { - await helper.runCommand(getWorkspace(), { - command: 'git checkout', - args: [branchName], - suppressError: true, - stderrToStdout: true, - }); - clonedBranch = await helper.getCurrentBranchName(getWorkspace()); - } - + const clonedBranch = await helper.getCurrentBranchName(getWorkspace()); + const branchName = await getPrBranchName(helper, octokit, context); if (branchName === clonedBranch) { await helper.runCommand(getWorkspace(), { diff --git a/yarn.lock b/yarn.lock index ea47076..9bd9980 100644 --- a/yarn.lock +++ b/yarn.lock @@ -772,10 +772,10 @@ "@actions/core" "^1.2.6" "@actions/github" "^4.0.0" -"@technote-space/github-action-helper@^4.3.1": - version "4.3.1" - resolved "https://registry.yarnpkg.com/@technote-space/github-action-helper/-/github-action-helper-4.3.1.tgz#e079ae025b174bc77de07a03d698361f29a43dbf" - integrity sha512-hYfo9Oxx/mX114AJy66p75B8wK69/59f7wIfAh8Ck4Jnv22LtRFMUgkRwnD9+q1ob777UwBqFcykXOSYdHfKQg== +"@technote-space/github-action-helper@^4.3.2": + version "4.3.2" + resolved "https://registry.yarnpkg.com/@technote-space/github-action-helper/-/github-action-helper-4.3.2.tgz#2c6650357713c50e23e7253de107361dd938e833" + integrity sha512-W0OTx9qVU3cY3Nc22VTluVJJWMQg4RzLARsNmZt/0A8qTvFwAAoxr0GBHW55VFsYHLNW4OOOElex1Tl1rBxzZA== dependencies: "@actions/core" "^1.2.6" "@actions/github" "^4.0.0"