fix(git): handle file renames between folders (#6020)
* git storage: handle file renames between folders --------- Co-authored-by: Nicolas Giard <github@ngpixel.com>
This commit is contained in:
parent
8fa771c4ce
commit
2e8585478f
@ -725,7 +725,7 @@ module.exports = class Page extends Model {
|
|||||||
const destinationHash = pageHelper.generateHash({ path: opts.destinationPath, locale: opts.destinationLocale, privateNS: opts.isPrivate ? 'TODO' : '' })
|
const destinationHash = pageHelper.generateHash({ path: opts.destinationPath, locale: opts.destinationLocale, privateNS: opts.isPrivate ? 'TODO' : '' })
|
||||||
|
|
||||||
// -> Move page
|
// -> Move page
|
||||||
const destinationTitle = (page.title === page.path ? opts.destinationPath : page.title)
|
const destinationTitle = (page.title === _.last(page.path.split('/')) ? _.last(opts.destinationPath.split('/')) : page.title)
|
||||||
await WIKI.models.pages.query().patch({
|
await WIKI.models.pages.query().patch({
|
||||||
path: opts.destinationPath,
|
path: opts.destinationPath,
|
||||||
localeCode: opts.destinationLocale,
|
localeCode: opts.destinationLocale,
|
||||||
@ -745,6 +745,7 @@ module.exports = class Page extends Model {
|
|||||||
...page,
|
...page,
|
||||||
destinationPath: opts.destinationPath,
|
destinationPath: opts.destinationPath,
|
||||||
destinationLocaleCode: opts.destinationLocale,
|
destinationLocaleCode: opts.destinationLocale,
|
||||||
|
title: destinationTitle,
|
||||||
destinationHash
|
destinationHash
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -146,10 +146,24 @@ module.exports = {
|
|||||||
const diff = await this.git.diffSummary(['-M', currentCommitLog.hash, latestCommitLog.hash])
|
const diff = await this.git.diffSummary(['-M', currentCommitLog.hash, latestCommitLog.hash])
|
||||||
if (_.get(diff, 'files', []).length > 0) {
|
if (_.get(diff, 'files', []).length > 0) {
|
||||||
let filesToProcess = []
|
let filesToProcess = []
|
||||||
|
const filePattern = /(.*?)(?:{(.*?))? => (?:(.*?)})?(.*)/
|
||||||
for (const f of diff.files) {
|
for (const f of diff.files) {
|
||||||
const fMoved = f.file.split(' => ')
|
const fMatch = f.file.match(filePattern)
|
||||||
const fName = fMoved.length === 2 ? fMoved[1] : fMoved[0]
|
const fNames = {
|
||||||
const fPath = path.join(this.repoPath, fName)
|
old: null,
|
||||||
|
new: null
|
||||||
|
}
|
||||||
|
if (!fMatch) {
|
||||||
|
fNames.old = f.file
|
||||||
|
fNames.new = f.file
|
||||||
|
} else if (!fMatch[2] && !fMatch[3]) {
|
||||||
|
fNames.old = fMatch[1]
|
||||||
|
fNames.new = fMatch[4]
|
||||||
|
} else {
|
||||||
|
fNames.old = (fMatch[1]+fMatch[2]+fMatch[4]).replace('//', '/'),
|
||||||
|
fNames.new = (fMatch[1]+fMatch[3]+fMatch[4]).replace('//', '/')
|
||||||
|
}
|
||||||
|
const fPath = path.join(this.repoPath, fNames.new)
|
||||||
let fStats = { size: 0 }
|
let fStats = { size: 0 }
|
||||||
try {
|
try {
|
||||||
fStats = await fs.stat(fPath)
|
fStats = await fs.stat(fPath)
|
||||||
@ -166,8 +180,8 @@ module.exports = {
|
|||||||
path: fPath,
|
path: fPath,
|
||||||
stats: fStats
|
stats: fStats
|
||||||
},
|
},
|
||||||
oldPath: fMoved[0],
|
oldPath: fNames.old,
|
||||||
relPath: fName
|
relPath: fNames.new
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await this.processFiles(filesToProcess, rootUser)
|
await this.processFiles(filesToProcess, rootUser)
|
||||||
|
Loading…
Reference in New Issue
Block a user