git storage: handle relocated files#4307
Merged
NGPixel merged 1 commit intorequarks:devfrom Sep 1, 2021
Merged
Conversation
EricFromCanada
commented
Aug 15, 2021
| const destinationHash = pageHelper.generateHash({ path: opts.destinationPath, locale: opts.destinationLocale, privateNS: opts.isPrivate ? 'TODO' : '' }) | ||
|
|
||
| // -> Move page | ||
| const destinationTitle = (page.title === page.path ? opts.destinationPath : page.title) |
Contributor
Author
There was a problem hiding this comment.
If the page has a title that was auto-generated from its filename, this updates its title to match the new filename.
| for (const item of files) { | ||
| const contentType = pageHelper.getContentType(item.relPath) | ||
| const fileExists = await fs.pathExists(item.file) | ||
| const fileExists = await fs.pathExists(item.file.path) |
Contributor
Author
There was a problem hiding this comment.
Fix for fileExists always being false.
Comment on lines
+227
to
+242
| if (fileExists && ((item.before === item.after) || (item.deletions === 0 && item.insertions === 0))) { | ||
| // Asset was renamed by git, so rename in DB | ||
| WIKI.logger.info(`(STORAGE/GIT) Asset marked as renamed: from ${item.oldPath} to ${item.relPath}`) | ||
|
|
||
| const fileHash = assetHelper.generateHash(item.relPath) | ||
| const assetToRename = await WIKI.models.assets.query().findOne({ hash: fileHash }) | ||
| if (assetToRename) { | ||
| await WIKI.models.assets.query().patch({ | ||
| filename: item.relPath, | ||
| hash: fileHash | ||
| }).findById(assetToRename.id) | ||
| await assetToRename.deleteAssetCache() | ||
| } else { | ||
| WIKI.logger.info(`(STORAGE/GIT) Asset was not found in the DB, nothing to rename: ${item.relPath}`) | ||
| } | ||
| continue |
Contributor
Author
There was a problem hiding this comment.
This should theoretically work for assets, but wasn't accessible in my testing because diff.files earlier in the file wasn't being populated when a binary was renamed. (Possibly related: steveukx/git-js#243)
Contributor
Author
There was a problem hiding this comment.
This is a limitation of git-js, which doesn't notice binaries being renamed: steveukx/git-js#885
NGPixel
approved these changes
Sep 1, 2021
|
This sounds really great. Good job and thanks 👍 💯 |
jionggyu
pushed a commit
to jionggyu/wiki-2.5.302-patch
that referenced
this pull request
Jul 9, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the git storage model does not handle files being renamed. This PR implements this by noticing when a filename in a diff contains
=>and relocating the corresponding page.