Logging fixes, fetch only when commit is not found

This commit is contained in:
Juan Ferrer 2022-04-30 21:14:23 +02:00
parent 0968ba1283
commit 216945ef0b
2 changed files with 15 additions and 9 deletions

22
myvc.js
View File

@ -125,11 +125,11 @@ class MyVC {
depVersion[1] === myVersion[1] && depVersion[1] === myVersion[1] &&
depVersion[2] === myVersion[2]; depVersion[2] === myVersion[2];
if (!isSameVersion) if (!isSameVersion)
throw new Error(`This version of MyVC differs from your package.json`); throw new Error(`MyVC version differs a lot from package.json, please run 'npm i' first to install the proper version`);
const isSameMinor = depVersion[3] === myVersion[3]; const isSameMinor = depVersion[3] === myVersion[3];
if (!isSameMinor) if (!isSameMinor)
console.warn(`Warning! Minor version of MyVC differs from your package.json`.yellow); console.warn(`Warning! MyVC minor version differs from package.json, maybe you shoud run 'npm i' to install the proper version`.yellow);
} }
// Load method // Load method
@ -312,19 +312,25 @@ class MyVC {
if (head && commitSha) { if (head && commitSha) {
let commit; let commit;
try { let notFound;
await repo.fetchAll(); commitSha = '9254aa7c35a1d25bf93629d2df4d5c1f87f21224'
} catch(err) {
console.warn(err.message.yellow);
}
try { try {
commit = await repo.getCommit(commitSha); commit = await repo.getCommit(commitSha);
notFound = false;
} catch (err) { } catch (err) {
if (err.errorFunction == 'Commit.lookup') if (err.errorFunction == 'Commit.lookup')
throw new Error(`Commit id (${commitSha}) not found, you may have to run 'git fetch' first`); notFound = true;
else else
throw err; throw err;
} }
if (notFound) {
console.warn(`Commit id (${commitSha}) not found trying to fetch from git remote`.yellow);
await repo.fetchAll();
commit = await repo.getCommit(commitSha);
}
const commitTree = await commit.getTree(); const commitTree = await commit.getTree();
const headTree = await head.getTree(); const headTree = await head.getTree();

View File

@ -1,6 +1,6 @@
{ {
"name": "myvc", "name": "myvc",
"version": "1.4.1", "version": "1.4.2",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "MySQL Version Control", "description": "MySQL Version Control",
"license": "GPL-3.0", "license": "GPL-3.0",