Fix Git Sync Deleting Files and Folders, Optimize the Initialize Process, Make sparse checkout optional #229
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.
Addressing #228 and subsequently #213 and possible #222
Also note that sparse checkout has been flaky at best for the 50+ sites that we have tried it on. We developed a better init process and don't recommend it.
Improved Initialization Process for the Plugin
The new initialization process for the plugin has been designed to be more robust and handle the local file state and the repository more efficiently. Below is an overview of the key steps involved:
Check Git Initialization: The process begins by checking if Git is already initialized in the current directory. If not, it proceeds with the initialization steps.
Setup Branches: It determines the branches to be used by fetching the remote branch configuration and setting up a local branch accordingly.
Initialize Git Repository:
Fetch and Integrate Changes:
Commit and Push:
The updates, along with any new files, are added and committed to the local repository with a predefined commit message.
This initial commit is then pushed to the upstream repository.
Sparse Checkout (Optional): If the 'sparse_checkout' configuration is set, this feature is enabled for the repository, allowing partial checkouts of the repository.
Handle Authentication: If needed, the process also includes authenticated access to the remote repository. Credentials are securely retrieved and used to update the remote URL.
Backup and Restore Untracked Files: Untracked files are safely backed up before the merge and restored after the merge process, ensuring no local changes are lost.
Rsync for File Synchronization: The rsync command is used to synchronize the directories while restoring untracked files, ensuring a reliable and efficient restoration process.
Clean Up: After the restoration of untracked files, the backup directory is cleanly removed to avoid clutter and potential conflicts in the future.
This enhanced initialization process aims to streamline the setup and synchronization of the local repository with the remote one, while ensuring that local changes are not overwritten or lost during updates. It makes the plugin more user-friendly and resilient to various repository states and configurations.