mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-21 21:45:42 -05:00
fix(plugin): restore user lockfile after upgrading
This commit is contained in:
parent
b2971bde6b
commit
0f67327a6c
@ -36,6 +36,7 @@ import {
|
|||||||
writePluginsJson,
|
writePluginsJson,
|
||||||
extractPluginName,
|
extractPluginName,
|
||||||
updateGlobalConfig,
|
updateGlobalConfig,
|
||||||
|
LOCKFILE_PATH,
|
||||||
} from "./plugin-data.js"
|
} from "./plugin-data.js"
|
||||||
import {
|
import {
|
||||||
UPSTREAM_NAME,
|
UPSTREAM_NAME,
|
||||||
@ -583,17 +584,51 @@ export async function handleUpgrade(argv) {
|
|||||||
console.log("Backing up your content")
|
console.log("Backing up your content")
|
||||||
execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`)
|
execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`)
|
||||||
await stashContentFolder(contentFolder)
|
await stashContentFolder(contentFolder)
|
||||||
|
|
||||||
|
const lockfileBackup = LOCKFILE_PATH + ".bak"
|
||||||
|
const hasLockfile = fs.existsSync(LOCKFILE_PATH)
|
||||||
|
if (hasLockfile) {
|
||||||
|
fs.copyFileSync(LOCKFILE_PATH, lockfileBackup)
|
||||||
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
"Pulling updates... you may need to resolve some `git` conflicts if you've made changes to components or plugins.",
|
"Pulling updates... you may need to resolve some `git` conflicts if you've made changes to components or plugins.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let pullOk = false
|
||||||
try {
|
try {
|
||||||
gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH)
|
gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH)
|
||||||
|
pullOk = true
|
||||||
} catch {
|
} catch {
|
||||||
|
if (hasLockfile) {
|
||||||
|
try {
|
||||||
|
fs.copyFileSync(lockfileBackup, LOCKFILE_PATH)
|
||||||
|
execSync(`git add ${LOCKFILE_PATH}`)
|
||||||
|
const remaining = execSync("git diff --name-only --diff-filter=U", {
|
||||||
|
encoding: "utf-8",
|
||||||
|
}).trim()
|
||||||
|
if (remaining.length === 0) {
|
||||||
|
execSync("git commit --no-edit")
|
||||||
|
pullOk = true
|
||||||
|
console.log(styleText("cyan", "Resolved quartz.lock.json merge conflict automatically."))
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Could not auto-resolve, fall through to manual resolution
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pullOk) {
|
||||||
console.log(styleText("red", "An error occurred above while pulling updates."))
|
console.log(styleText("red", "An error occurred above while pulling updates."))
|
||||||
await popContentFolder(contentFolder)
|
await popContentFolder(contentFolder)
|
||||||
|
if (fs.existsSync(lockfileBackup)) fs.unlinkSync(lockfileBackup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasLockfile && fs.existsSync(lockfileBackup)) {
|
||||||
|
fs.copyFileSync(lockfileBackup, LOCKFILE_PATH)
|
||||||
|
fs.unlinkSync(lockfileBackup)
|
||||||
|
}
|
||||||
|
|
||||||
await popContentFolder(contentFolder)
|
await popContentFolder(contentFolder)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user