mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Chore: Default plugins: Refactor git checkout
in default plugins build (#9812)
This commit is contained in:
parent
0e45336140
commit
9a26e8aafd
@ -570,6 +570,7 @@ packages/default-plugins/build.js
|
||||
packages/default-plugins/buildDefaultPlugins.js
|
||||
packages/default-plugins/commands/buildAll.js
|
||||
packages/default-plugins/commands/editPatch.js
|
||||
packages/default-plugins/utils/getCurrentCommitHash.js
|
||||
packages/default-plugins/utils/getPathToPatchFileFor.js
|
||||
packages/default-plugins/utils/readRepositoryJson.js
|
||||
packages/default-plugins/utils/waitForCliInput.js
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -550,6 +550,7 @@ packages/default-plugins/build.js
|
||||
packages/default-plugins/buildDefaultPlugins.js
|
||||
packages/default-plugins/commands/buildAll.js
|
||||
packages/default-plugins/commands/editPatch.js
|
||||
packages/default-plugins/utils/getCurrentCommitHash.js
|
||||
packages/default-plugins/utils/getPathToPatchFileFor.js
|
||||
packages/default-plugins/utils/readRepositoryJson.js
|
||||
packages/default-plugins/utils/waitForCliInput.js
|
||||
|
@ -10,6 +10,7 @@ import { glob } from 'glob';
|
||||
import readRepositoryJson from './utils/readRepositoryJson';
|
||||
import waitForCliInput from './utils/waitForCliInput';
|
||||
import getPathToPatchFileFor from './utils/getPathToPatchFileFor';
|
||||
import getCurrentCommitHash from './utils/getCurrentCommitHash';
|
||||
|
||||
type BeforeEachInstallCallback = (buildDir: string, pluginName: string)=> Promise<void>;
|
||||
|
||||
@ -41,20 +42,21 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall:
|
||||
}
|
||||
|
||||
chdir(pluginDir);
|
||||
const currentCommitHash = (await execCommand(['git', 'rev-parse', 'HEAD'])).trim();
|
||||
const expectedCommitHash = repositoryData.commit;
|
||||
|
||||
if (currentCommitHash !== expectedCommitHash) {
|
||||
logStatus(`Switching to commit ${expectedCommitHash}`);
|
||||
await execCommand(['git', 'switch', repositoryData.branch]);
|
||||
logStatus(`Switching to commit ${expectedCommitHash}`);
|
||||
await execCommand(['git', 'switch', repositoryData.branch]);
|
||||
|
||||
try {
|
||||
await execCommand(['git', 'checkout', expectedCommitHash]);
|
||||
} catch (error) {
|
||||
logStatus(`git checkout failed with error ${error}. Fetching...`);
|
||||
await execCommand(['git', 'fetch']);
|
||||
await execCommand(['git', 'checkout', expectedCommitHash]);
|
||||
}
|
||||
try {
|
||||
await execCommand(['git', 'checkout', expectedCommitHash]);
|
||||
} catch (error) {
|
||||
logStatus(`git checkout failed with error ${error}. Fetching...`);
|
||||
await execCommand(['git', 'fetch']);
|
||||
await execCommand(['git', 'checkout', expectedCommitHash]);
|
||||
}
|
||||
|
||||
if (await getCurrentCommitHash() !== expectedCommitHash) {
|
||||
throw new Error(`Unable to checkout commit ${expectedCommitHash}`);
|
||||
}
|
||||
|
||||
logStatus('Copying repository files...');
|
||||
|
7
packages/default-plugins/utils/getCurrentCommitHash.ts
Normal file
7
packages/default-plugins/utils/getCurrentCommitHash.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { execCommand } from '@joplin/utils';
|
||||
|
||||
const getCurrentCommitHash = async () => {
|
||||
return (await execCommand(['git', 'rev-parse', '--verify', 'HEAD^{commit}'])).trim();
|
||||
};
|
||||
|
||||
export default getCurrentCommitHash;
|
Loading…
Reference in New Issue
Block a user