Skip to content

Commit cb94e01

Browse files
Alan Shawhugomrdias
authored andcommitted
fix: specify remote for branch to checkout (#465)
I have many different remotes becuase of checking out branches for external contributors. Git is confused because the branch exists on multiple remotes and fails with: ``` error: pathspec 'build/last-successful' did not match any file(s) known to git hint: 'build/last-successful' matched more than one remote tracking branch. ``` This fixes that error.
1 parent 7ee3d14 commit cb94e01

File tree

9 files changed

+38
-16
lines changed

9 files changed

+38
-16
lines changed

cmds/publish-rc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = {
99
type: 'string',
1010
default: 'build/last-successful'
1111
},
12+
remote: {
13+
describe: 'Which remote to use',
14+
type: 'string',
15+
default: 'origin'
16+
},
1217
distTag: {
1318
describe: 'The dist tag to publish the rc as',
1419
type: 'string',

cmds/update-last-successful-build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = {
99
type: 'string',
1010
default: 'build/last-successful'
1111
},
12+
remote: {
13+
describe: 'Which remote to use',
14+
type: 'string',
15+
default: 'origin'
16+
},
1217
message: {
1318
describe: 'The message to use when adding the shrinkwrap and yarn.lock file',
1419
type: 'string',

cmds/update-rc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = {
99
describe: 'Where the latest release branch is',
1010
type: 'string'
1111
},
12+
remote: {
13+
describe: 'Which remote to use',
14+
type: 'string',
15+
default: 'origin'
16+
},
1217
distTag: {
1318
describe: 'The dist tag to publish the rc as',
1419
type: 'string',

cmds/update-release-branch-lockfiles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ module.exports = {
88
describe: 'Which branch to update',
99
type: 'string'
1010
},
11+
remote: {
12+
describe: 'Which remote to use',
13+
type: 'string',
14+
default: 'origin'
15+
},
1116
message: {
1217
describe: 'The message to use when adding the shrinkwrap and yarn.lock file',
1318
type: 'string',

src/publish-rc/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function publishRc (opts) {
2121
await exec('git', ['fetch'])
2222

2323
console.info(`Checking out branch ${opts.branch}`) // eslint-disable-line no-console
24-
await exec('git', ['checkout', opts.branch])
24+
await exec('git', ['checkout', '--track', `${opts.remote}/${opts.branch}`])
2525

2626
console.info('Removing dependencies') // eslint-disable-line no-console
2727
await exec('rm', ['-rf', 'node_modules', 'package-lock.json'])
@@ -41,7 +41,7 @@ async function publishRc (opts) {
4141
console.info('Creating release branch', newVersionBranch) // eslint-disable-line no-console
4242

4343
await exec('git', ['checkout', '-b', newVersionBranch])
44-
await exec('git', ['push', 'origin', `${newVersionBranch}:${newVersionBranch}`], {
44+
await exec('git', ['push', opts.remote, `${newVersionBranch}:${newVersionBranch}`], {
4545
quiet: true
4646
})
4747

@@ -66,7 +66,8 @@ async function publishRc (opts) {
6666
publish: true,
6767
ghrelease: true,
6868
docs: true,
69-
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN
69+
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN,
70+
remote: opts.remote
7071
})
7172
}
7273

src/release/push.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const git = require('simple-git')(process.cwd())
44
const pify = require('pify')
55
const execa = require('execa')
66

7-
async function push () {
8-
const remote = 'origin'
7+
async function push (opts) {
8+
const remote = opts.remote || 'origin'
99
const branch = (await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
1010
cwd: process.cwd()
1111
})).stdout

src/update-last-successful-build/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ async function findCurrentBranch () {
1010
return result.stdout.replace('ref: ', '').trim()
1111
}
1212

13-
async function findMasterCommit () {
14-
const result = await exec('git', ['show-ref', '-s', 'origin/master'])
13+
async function findMasterCommit (opts) {
14+
const result = await exec('git', ['show-ref', '-s', `${opts.remote}/master`])
1515

1616
return result.stdout.trim()
1717
}
1818

19-
async function isHeadOfMaster () {
20-
const master = await findMasterCommit()
19+
async function isHeadOfMaster (opts) {
20+
const master = await findMasterCommit(opts)
2121
const branch = await findCurrentBranch()
2222

2323
// we either have master checked out or a single commit
2424
return branch === 'refs/heads/master' || branch === master
2525
}
2626

2727
async function updateLastSuccessfulBuild (opts) {
28-
if (!isHeadOfMaster()) {
28+
if (!isHeadOfMaster(opts)) {
2929
console.info('Will only run on the master branch') // eslint-disable-line no-console
3030

3131
return
@@ -60,7 +60,7 @@ async function updateLastSuccessfulBuild (opts) {
6060

6161
try {
6262
console.info(`Deleting remote ${opts.branch} branch`) // eslint-disable-line no-console
63-
await exec('git', ['push', 'origin', `:${opts.branch}`], {
63+
await exec('git', ['push', opts.remote, `:${opts.branch}`], {
6464
quiet: true
6565
})
6666
} catch (err) {
@@ -70,7 +70,7 @@ async function updateLastSuccessfulBuild (opts) {
7070
}
7171

7272
console.info(`Pushing ${opts.branch} branch`) // eslint-disable-line no-console
73-
await exec('git', ['push', 'origin', `${tempBranch}:${opts.branch}`], {
73+
await exec('git', ['push', opts.remote, `${tempBranch}:${opts.branch}`], {
7474
quiet: true
7575
})
7676
}

src/update-rc/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function updateRc (opts) {
2121
await exec('git', ['fetch'])
2222

2323
console.info(`Checking out branch ${opts.branch}`) // eslint-disable-line no-console
24-
await exec('git', ['checkout', opts.branch])
24+
await exec('git', ['checkout', '--track', `${opts.remote}/${opts.branch}`])
2525

2626
console.info('Removing dependencies') // eslint-disable-line no-console
2727
await exec('rm', ['-rf', 'node_modules', 'package-lock.json'])
@@ -44,7 +44,8 @@ async function updateRc (opts) {
4444
publish: true,
4545
ghrelease: true,
4646
docs: true,
47-
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN
47+
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN,
48+
remote: opts.remote
4849
})
4950
}
5051

src/update-release-branch-lockfiles/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function updateReleaseBranchLockfiles (opts) {
2222
await exec('git', ['fetch'])
2323

2424
console.info(`Checking out branch ${opts.branch}`) // eslint-disable-line no-console
25-
await exec('git', ['checkout', opts.branch])
25+
await exec('git', ['checkout', '--track', `${opts.remote}/${opts.branch}`])
2626

2727
console.info('Removing dependencies') // eslint-disable-line no-console
2828
await exec('rm', ['-rf', 'node_modules', 'package-lock.json', 'yarn.lock', 'npm-shrinkwrap.json'])
@@ -50,7 +50,7 @@ async function updateReleaseBranchLockfiles (opts) {
5050
}
5151

5252
console.info(`Pushing ${opts.branch} branch`) // eslint-disable-line no-console
53-
await exec('git', ['push', 'origin', `${opts.branch}:${opts.branch}`], {
53+
await exec('git', ['push', opts.remote, `${opts.branch}:${opts.branch}`], {
5454
quiet: true
5555
})
5656
}

0 commit comments

Comments
 (0)