fix: remove hack to workaround GitHub Rebase & Merge
This commit is contained in:
parent
1edae67326
commit
844e0b07e0
@ -25,7 +25,7 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
|||||||
const branchTags = await pReduce(
|
const branchTags = await pReduce(
|
||||||
tags,
|
tags,
|
||||||
async (tags, {gitTag, ...rest}) =>
|
async (tags, {gitTag, ...rest}) =>
|
||||||
(await isRefInHistory(gitTag, branch.name, true, {cwd, env}))
|
(await isRefInHistory(gitTag, branch.name, {cwd, env}))
|
||||||
? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}]
|
? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}]
|
||||||
: tags,
|
: tags,
|
||||||
[]
|
[]
|
||||||
|
17
lib/git.js
17
lib/git.js
@ -1,4 +1,3 @@
|
|||||||
const {matches, pick, memoize} = require('lodash');
|
|
||||||
const gitLogParser = require('git-log-parser');
|
const gitLogParser = require('git-log-parser');
|
||||||
const getStream = require('get-stream');
|
const getStream = require('get-stream');
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
@ -70,21 +69,16 @@ async function getBranches(repositoryUrl, execaOpts) {
|
|||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getBranchCommits = memoize((branch, execaOpts) =>
|
|
||||||
getStream.array(gitLogParser.parse({_: branch}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}}))
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the `ref` is in the direct history of a given branch.
|
* Verify if the `ref` is in the direct history of a given branch.
|
||||||
*
|
*
|
||||||
* @param {String} ref The reference to look for.
|
* @param {String} ref The reference to look for.
|
||||||
* @param {String} branch The branch for which to check if the `ref` is in history.
|
* @param {String} branch The branch for which to check if the `ref` is in history.
|
||||||
* @param {Boolean} findRebasedTags Weither consider in history tags associated with a commit that was rebased to another branch (i.e. GitHub Rebase and Merge feature).
|
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
|
* @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
|
||||||
*/
|
*/
|
||||||
async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) {
|
async function isRefInHistory(ref, branch, execaOpts) {
|
||||||
if (!(await isRefExists(branch, execaOpts))) {
|
if (!(await isRefExists(branch, execaOpts))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -94,13 +88,6 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) {
|
|||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.exitCode === 1) {
|
if (error.exitCode === 1) {
|
||||||
if (findRebasedTags) {
|
|
||||||
const [tagCommit] = await getStream.array(
|
|
||||||
gitLogParser.parse({_: ref, n: '1'}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}})
|
|
||||||
);
|
|
||||||
return (await getBranchCommits(branch, execaOpts)).some(matches(pick(tagCommit, ['message', 'author'])));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +275,7 @@ async function verifyBranchName(branch, execaOpts) {
|
|||||||
async function isBranchUpToDate(repositoryUrl, branch, execaOpts) {
|
async function isBranchUpToDate(repositoryUrl, branch, execaOpts) {
|
||||||
const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts);
|
const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts);
|
||||||
try {
|
try {
|
||||||
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, false, execaOpts);
|
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, execaOpts);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debug(error);
|
debug(error);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import test from 'ava';
|
import test from 'ava';
|
||||||
import getTags from '../../lib/branches/get-tags';
|
import getTags from '../../lib/branches/get-tags';
|
||||||
import {gitRepo, gitCommits, gitTagVersion, gitCheckout, merge, changeAuthor} from '../helpers/git-utils';
|
import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from '../helpers/git-utils';
|
||||||
|
|
||||||
test('Get the valid tags', async t => {
|
test('Get the valid tags', async t => {
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
@ -175,28 +175,3 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
|||||||
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined, gitHead: commits[0].hash}]},
|
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined, gitHead: commits[0].hash}]},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get the tag on branch where commits have been rebased', async t => {
|
|
||||||
const {cwd} = await gitRepo();
|
|
||||||
const commits = await gitCommits(['First'], {cwd});
|
|
||||||
await gitCheckout('next', true, {cwd});
|
|
||||||
commits.push(...(await gitCommits(['Second/n/n/commit body'], {cwd})));
|
|
||||||
await gitTagVersion('v1.0.0@next', undefined, {cwd});
|
|
||||||
await gitCheckout('master', false, {cwd});
|
|
||||||
await merge('next', {cwd});
|
|
||||||
// Simulate GitHub "Rebase and Merge" by changing the committer info, which will result in a new commit sha and losing the tag
|
|
||||||
await changeAuthor(commits[1].hash, {cwd});
|
|
||||||
|
|
||||||
const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [{name: 'master'}, {name: 'next'}]);
|
|
||||||
|
|
||||||
t.deepEqual(result, [
|
|
||||||
{
|
|
||||||
name: 'master',
|
|
||||||
tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'next',
|
|
||||||
tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
@ -105,10 +105,10 @@ test('Verify if the commit `sha` is in the direct history of the current branch'
|
|||||||
const otherCommits = await gitCommits(['Second'], {cwd});
|
const otherCommits = await gitCommits(['Second'], {cwd});
|
||||||
await gitCheckout('master', false, {cwd});
|
await gitCheckout('master', false, {cwd});
|
||||||
|
|
||||||
t.true(await isRefInHistory(commits[0].hash, 'master', false, {cwd}));
|
t.true(await isRefInHistory(commits[0].hash, 'master', {cwd}));
|
||||||
t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', false, {cwd}));
|
t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', {cwd}));
|
||||||
t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', false, {cwd}));
|
t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', {cwd}));
|
||||||
await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', false, {cwd}));
|
await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', {cwd}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Verify if a branch exists', async t => {
|
test('Verify if a branch exists', async t => {
|
||||||
|
@ -256,16 +256,3 @@ export async function mergeFf(ref, execaOpts) {
|
|||||||
export async function rebase(ref, execaOpts) {
|
export async function rebase(ref, execaOpts) {
|
||||||
await execa('git', ['rebase', ref], execaOpts);
|
await execa('git', ['rebase', ref], execaOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changeAuthor(sha, execaOpts) {
|
|
||||||
await execa(
|
|
||||||
'git',
|
|
||||||
[
|
|
||||||
'filter-branch',
|
|
||||||
'-f',
|
|
||||||
'--env-filter',
|
|
||||||
`if [[ "$GIT_COMMIT" = "${sha}" ]]; then export GIT_COMMITTER_NAME="New Author" GIT_COMMITTER_EMAIL="author@test.com"; fi`,
|
|
||||||
],
|
|
||||||
execaOpts
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user